This page documents a user-defined function that you can copy and paste into your addon. Replace <PREFIX> with your AddOn's prefix to avoid conflicts between different versions of these functions.
User defined functions < GetSlashFunc

Returns the function called when using /cmd.

slashFunction = USERAPI GetSlashFunc(cmd)

Function Parameters Edit

Arguments Edit

the slash command to search for

Returns Edit

the actual function called when executing the cmd.

Example Edit

local func = GetSlashFunc("/quit")
SLASH_MYQUIT1 = "/quit"
SLASH_MYQUIT2 = "/exit"
SlashCmdList["MYQUIT"] = function(msg)
    if msg == "now" then
    elseif func then


Quit now instead of in 30 seconds when /quit now is used.


-- returns a slash command function on success or an informative error function on failure.
local function GetSlashFunc(cmd)
    if not cmd then
        return function(cmd) print("You must supply a command.") end
    if cmd:sub(1, 1) ~= "/" then
        cmd = "/" .. cmd
    for id, val in pairs(_G) do
        if id:sub(1, 5) == "SLASH" and val == cmd then
            local slashID = id:match("SLASH_(%a*)%d*")
            return SlashCmdList[slashID]
    -- Didn't find one?
    return function(cmd) print(cmd, "doesn't exist.") end

Notes Edit

  • This will not work to hook secure commands such as /target, /cast, /focus, etc. The functions that are called with those commands are not globally accessible to addon scripts and, if they were, you would just end up breaking stuff.
  • If an addon creates its slash command after yours, yours will no longer work (as per usual).

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.