Skip to content

Instantly share code, notes, and snippets.

@veeponym
Created February 15, 2023 13:06
Show Gist options
  • Save veeponym/ce41e1fc4ea02f90f12a2f17bbd8e984 to your computer and use it in GitHub Desktop.
Save veeponym/ce41e1fc4ea02f90f12a2f17bbd8e984 to your computer and use it in GitHub Desktop.
-- Define a help object
local help = {}
-- Define a function to register the commands
function help:registerCommands(client, slash)
-- Define a slash command for help
slash:registerCommand('help', 'Get the list of commands', function(interaction)
-- Get the list of commands from the slash object
local commands = slash:getCommands()
-- Create a table to store the command names and descriptions
local commandList = {}
-- Loop through the commands
for _, command in ipairs(commands) do
-- Add the command name and description to the table
table.insert(commandList, command.name .. ': ' .. command.description)
end
-- Join the table elements with a newline
local commandString = table.concat(commandList, '\n')
-- Reply with the command list
interaction:reply('Here are the commands you can use:\n' .. commandString)
end)
end
-- Define a function to unregister the commands
function help:unregisterCommands(client, slash)
-- Unregister the slash command for help
slash:unregisterCommand('help')
end
-- Return the help object
return help
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment