View Single Post
12-28-12, 10:17 PM   #3
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Please use [code] tags around your code so it's actually readable. I'm not sure how you're formatting your actual Lua file, but once proper formatting is applied to the code you posted, there are several glaringly obvious problems:

Code:
SLASH_DISCORD1, SLASH_DISCORD2 = '/discord', '/dc';
function SlashCmdList.DISCORD(msg, editbox) 
	gl = GetGuildLevel()
	SendChatMessage("<Discord>("gl") is recruiting all levels. We are a social leveling guild with 7 bank tabs, website, vent & years of exp. So if you want help leveling, raiding, or just want to socialize, pst. We have a guild repair fund. Pst for invite.", "channel",nil,1)
1) You're missing an "end" for your slash command handler function.

2) You're missing string concatenation operators around the "gl" variable you're trying to insert into the middle of your string.

Both of those problems are triggering Lua errors; enabling Lua error display -- or better yet, installing a dedicated error display addon like BugSack -- is the first thing you should do when trying to write or even just edit an addon. Without an error display, you are working blind.

Also, you don't actually need a variable, since you can just concatenate the result directly -- "<Discord>(" .. GetGuildLevel() .. ") is recruiting..." -- but if you want to use one anyway, it should absolutely not be a global variable, and absolutely should be a local one.

I'd also suggest picking one style of string delimiter -- single quotes or double quotes -- and use it consistently. Double quotes are more popular, since apostrophes are more likely to be in the middle of a string, either one is fine.

Finally, I'm not 100% sure, but the channel name (eg. "CHANNEL") passed to SendChatMessage may need to be capitalized; even if it's not required, you should do it anyway to maintain consistency with the official API usage in Blizzard's code and the API documentation on places like Wowpedia (which follows Blizzard's usage).

Here is your code revised to address the above issues and preferrentially send to the Trade channel when possible.

Code:
SLASH_DISCORD1, SLASH_DISCORD2 = "/discord", "/dc"
function SlashCmdList.DISCORD(msg, editbox)
	local _, _, _, _, _, active = GetChannelDisplayInfo(2)
	SendChatMessage("<Discord>(" .. GetGuildLevel() .. ") is recruiting all levels. We are a social leveling guild with 7 bank tabs, website, vent & years of exp. So if you want help leveling, raiding, or just want to socialize, pst. We have a guild repair fund. Pst for invite.", "CHANNEL", nil, active and 2 or 1)
end
In actual usage, though, you may want to do a little more work to make sure that channels 1 and 2 are actually General and Trade, since it isn't guaranteed that they will be.

Finally, your message seems a little wordy; I'd suggest trying to shorten it as much as possible. The less people have to read, the more likely they are to read at all.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote