有没有办法在 shout 或 say 中获取最后一条聊天消息?
Is there a way to get the last chat massage in shout or say?
我想在最后一条消息中搜索几个字符串,然后用其他字符串替换这些字符串回显消息。
我搜索了多个文档,但没有找到获取最后一条消息的方法。
这是我问的第一个论坛,因为我已经有一个帐户,所以没有真正的起点可以给你。
提前致谢!
WoW API 无法获取特定频道的最后一条聊天消息。您将必须分别处理 CHAT_MSG_CHANNEL
event (see Event Handling) to read all messages, and store the newest one. Specifically for the say or yell (shout) channels there are the CHAT_MSG_SAY
and CHAT_MSG_YELL
个事件。
为此,您的插件需要拥有一个框架,这些框架可以注册事件处理程序,您必须将从该处理程序收到的最后一条消息存储在脚本的局部变量中(我们称之为 last_message
).然后当你的另一段代码执行时,你可以读取 last_message
变量:
local frame = CreateFrame("FRAME", "FooAddonFrame");
local last_message = nil;
frame:RegisterEvent("CHAT_MSG_CHANNEL");
local function eventHandler(self, event, ...)
-- Look up the arguments that are given to your specific event
-- and assign them to variables in order by retrieving them from
-- the `...` variable arguments
local msg, author, language, channel = ...
print("Hello World! Hello " .. event);
last_message = msg
end
frame:SetScript("OnEvent", eventHandler);
我想在最后一条消息中搜索几个字符串,然后用其他字符串替换这些字符串回显消息。
我搜索了多个文档,但没有找到获取最后一条消息的方法。 这是我问的第一个论坛,因为我已经有一个帐户,所以没有真正的起点可以给你。
提前致谢!
WoW API 无法获取特定频道的最后一条聊天消息。您将必须分别处理 CHAT_MSG_CHANNEL
event (see Event Handling) to read all messages, and store the newest one. Specifically for the say or yell (shout) channels there are the CHAT_MSG_SAY
and CHAT_MSG_YELL
个事件。
为此,您的插件需要拥有一个框架,这些框架可以注册事件处理程序,您必须将从该处理程序收到的最后一条消息存储在脚本的局部变量中(我们称之为 last_message
).然后当你的另一段代码执行时,你可以读取 last_message
变量:
local frame = CreateFrame("FRAME", "FooAddonFrame");
local last_message = nil;
frame:RegisterEvent("CHAT_MSG_CHANNEL");
local function eventHandler(self, event, ...)
-- Look up the arguments that are given to your specific event
-- and assign them to variables in order by retrieving them from
-- the `...` variable arguments
local msg, author, language, channel = ...
print("Hello World! Hello " .. event);
last_message = msg
end
frame:SetScript("OnEvent", eventHandler);