View Single Post
08-02-20, 01:24 AM   #1
Lev
A Kobold Labourer
Join Date: Aug 2020
Posts: 1
I need an event that occurs later than PLAYER_ENTERING_WORLD

Not sure how many people use Communities at all, but there's an annoying bug where community chat can be hidden when you log in. To fix this in-game, you can open your Chat Channels list and click the box next to the community chat channel to hide it, and then click it again to reshow it.

With this knowledge, I found ChatFrame_RemoveChannel and ChatFrame_AddChannel serve the same purpose as clicking that box in the chat channel UI.
Code:
ChatFrame_RemoveChannel(DEFAULT_CHAT_FRAME, "Community:XXXXXXX:1")
ChatFrame_AddChannel(DEFAULT_CHAT_FRAME, "Community:XXXXXXX:1") 
(the XXXXXXX is a string of numbers that's basically the community's ID, 
not sure if I should post that here)
I can run these in-game via /script and it fixes the chat bug. I've been having an issue automating it though, because the chat doesn't seem to bug out until after loading into WoW. I can run RemoveChannel on the PLAYER_LOGIN event perfectly fine, but AddChannel seems to need a delay. PLAYER_ENTERING_WORLD is too soon and it doesn't work. The *only* solution that has worked is using a 20 second timer after PLAYER_ENTERING_WORLD, but that probably isn't a consistent solution if I share this addon with my community. Does anyone have any ideas?

Code:
local frame=CreateFrame("Frame");
frame:RegisterEvent("PLAYER_LOGIN");
frame:RegisterEvent("PLAYER_ENTERING_WORLD")
frame:SetScript("OnEvent",function(self,event,...)
    if (event=="PLAYER_LOGIN") then
    ChatFrame_RemoveChannel(DEFAULT_CHAT_FRAME, "Community:XXXXXXX:1")
    elseif (event=="PLAYER_ENTERING_WORLD") then
    C_Timer.After(20, function() ChatFrame_AddChannel(DEFAULT_CHAT_FRAME, "Community:XXXXXXX:1") end)
    frame:UnregisterAllEvents() 
    end
end)
  Reply With Quote