zephyr.commands
Register slash command and autocomplete handlers at module load time.
2 functions
register
zephyr.commands.register(path, definition, handler)Register a slash command handler and command spec.
path is a command path array (e.g. { "ticket", "panel" }) with at least one non-empty part. definition may be a full metadata table, an option array, or a shorthand option map. handler is called with a command context table.
Parameters
pathstring[]Command path, e.g. { "ticket", "panel" }.
definitiontableCommand metadata (description, permissions/required_permissions, options), an option array, or a shorthand option map.
handlerfunctionCalled with the command context table when the command is invoked.
Returns
Nothing.
Example
zephyr.commands.register({ "debug", "echo" }, {
description = "Echo text.",
options = {
{ name = "text", description = "Text to echo.", type = "string", required = true },
},
}, function(ctx)
zephyr.discord.respond({ content = ctx.options.text, ephemeral = true })
end)register_autocomplete
zephyr.commands.register_autocomplete(path, handler)Register an autocomplete handler for a slash command path.
Options opt into autocomplete with autocomplete = true in their command option spec. The handler receives { kind = "autocomplete", command, option, value, guild_id, user_id, options } and returns up to 25 { name, value } string choices.
Parameters
pathstring[]Command path, e.g. { "ranked", "equipo" }.
handlerfunctionCalled with the autocomplete context table.
Returns
Nothing.
Example
zephyr.commands.register_autocomplete({ "debug", "echo" }, function(ctx)
return { { name = ctx.value, value = ctx.value } }
end)