How to execute slash command in lua?

I was wondering if there is a way to execute slash command in lua such as “/recount show” to open recount from my addon?

I tried to use SendChatMessage but it only saying the command.
I tried this code below from the API and it do nothing… no lua error. Nothing!

local _G = _G
function RunSlashCmd(cmd)
local slash, rest = cmd:match(“^(%S+)%s*(.-)$”)
for name, func in pairs(SlashCmdList) do
local i, slashCmd = 1
repeat
slashCmd, i = G["SLASH"…name…i], i + 1
if slashCmd == slash then
return true, func(rest)
end
until not slashCmd
end
– Okay, so it’s not a slash command. It may also be an emote.
local i = 1
while _G[“EMOTE” … i … “_TOKEN”] do
local j, cn = 2, _G[“EMOTE” … i … “_CMD1”]
while cn do
if cn == slash then
return true, DoEmote(_G[“EMOTE” … i … “_TOKEN”], rest);
end
j, cn = j+1, _G[“EMOTE” … i … “_CMD” … j]
end
i = i + 1
end
end

RunSlashCmd(“/help”)

Im new in lua programming I need help plz.

SlashCmdList["ACECONSOLE_RECOUNT"]("show")

Replace “show” with the /recount parameter you want to use.

What goes in the SlashCmdList["..."] depends on the addon and any libraries it may use (Recount uses Ace libraries hence the ACECONSOLE_ prefix)

2 Likes

Hey thanks Fizzlemizz! this is exactly what I was looking for.