This works for me fine on Retail (I didn't bother writing code to join a specific chat channel and get the index from that)
I also didn't test it with another player or account, just with myself
Lua Code:
local prefix = "SomePrefix123"
local playerName = UnitName("player")
local function OnEvent(self, event, ...)
if event == "CHAT_MSG_ADDON" then
print(event, ...)
elseif event == "PLAYER_ENTERING_WORLD" then
local isInitialLogin, isReloadingUi = ...
if isInitialLogin or isReloadingUi then
C_ChatInfo.RegisterAddonMessagePrefix(prefix)
C_ChatInfo.SendAddonMessage(prefix, "Hello world!", "CHANNEL", 5)
end
end
end
local f = CreateFrame("Frame")
f:RegisterEvent("CHAT_MSG_ADDON")
f:RegisterEvent("PLAYER_ENTERING_WORLD")
f:SetScript("OnEvent", OnEvent)