1. Install
BugSack. Based on your description of the problem, you're almost certainly getting an error message that will tell you exactly what and where the problem is in your code, but Blizzard in their infinite wisdom decided not to display error messages by default, and their optional error display is useless for development anyway, since it can't show you errors that occur during loading, which is when this kind of error (most likely a syntax error) is happening.
2. That code is rather messy anyway. Here's a better version (feel free to delete all the comments to shorten it up once you've gone over it and understand what's going on):
Code:
-- Put all the commands and sounds here so it's easier to add more
-- without ending up with a gigantic if-else chain:
local sounds = {
chaim = "Interface\\AddOns\\Adry\\chaim.mp3",
cc = "Interface\\AddOns\\Adry\\CCing.mp3",
dmg = "Interface\\AddOns\\Adry\\big_damage.mp3",
monk = "Interface\\AddOns\\Adry\\monk.mp3",
}
local f = CreateFrame("Frame")
f:RegisterEvent("CHAT_MSG_ADDON")
f:SetScript("OnEvent", function(self, event, prefix, message, channel, sender)
if prefix ~= "adry" then return end
-- You may also want to return out if this is your own message,
-- and/or if the message wasn't sent by a group member,
-- eg. if it was whispered to you by a stranger.
local soundFile = sounds[message]
if not soundFile then return end
PlaySoundFile(soundFile, "Master")
end)
SLASH_ADRY1 = "/adry"
SlashCmdList.ADRY = function(message)
-- Find the right channel for your current group type:
local channel
if IsInGroup(LE_PARTY_CATEGORY_INSTANCE) then
channel = "INSTANCE_CHAT"
elseif IsInRaid() then
channel = "RAID"
elseif IsInGroup() then
channel = "PARTY"
else
-- Nobody to send to. Quit.
return
end
-- Clean up the message by removing leading/trailing spaces,
-- and converting to lowercase so it will match the table keys:
message = strlower(strtrim(message))
-- Send it:
SendAddonMessage("adry", message, channel)
end
RegisterAddonMessagePrefix("adry")