Slash commands
guideThe slash command structure, its path, description and trigger, and pushing it to Discord.
This page covers the slash command structure: its header, entries, trigger, and how a script pushes it to Discord. You're assumed to have a bot named "my-bot" logged in and to have read the commands overview.
How a slash command works
A slash command structure is a model, declared next to your bot's on ready block, not inside it. Its header names the command and its arguments; its trigger runs once a user actually uses /name on Discord. Nothing reaches Discord at load, reload or unload: a script pushes the result explicitly, typically from on guild ready.
slash command ping: description: Pong! trigger: reply with hidden "Pong! (%used slash command%)"
on guild ready: update the discord commands (all structured application commands) in event-guild
/ping now runs the trigger above and replies with an ephemeral Pong! (ping).
slash command <([\p{L}\p{N}_'-]+( [\p{L}\p{N}_'-]+){0,2})( .+)?$>Declares a slash command: its path (up to three words: command, group, subcommand), its arguments as '<name: type>' (wrapped in [ ] when optional), and a trigger that runs when it is used. Every argument is available as '{_name}' and as 'arg-1' / 'user argument' in the trigger.In v4 the structure registered itself on Discord, with bot: and guilds: entries; in v5 the structure registers nothing, and a script calls update the discord commands ... from on guild ready (or on ready for global commands). Nothing is deleted from Discord at unload or shutdown, either: pushing again is what removes a command. Arguments are declared in the header as <name: type> instead of an arguments: list, and can't have a default value, since Discord has none. Cancelling on cooldown still lets the command run.
Entries
Every entry below is optional; description defaults to "No description provided".
Entry | Default | Accepted values |
|---|---|---|
"No description provided" | text, or a section of | |
the header's own name | a section of | |
arguments | none | a section: per argument, |
| none for a root or a group | a section of Skript code |
enabled for, disabled, nsfw, contexts, integration types, cooldown, cooldown scope and on cooldown restrict and localise the command; see Command settings.
Subcommands and groups
A path is one to three lowercase words: a command, an optional group, an optional subcommand. Two structures sharing the first word merge into one Discord command:
slash command mod ban <target: member> [<reason: string>]: description: Ban a member trigger: reply with hidden "Would ban %{_target}%" slash command mod kick <target: member>: description: Kick a member trigger: reply with hidden "Would kick %{_target}%"
mod ban and mod kick become one /mod with two subcommands. A path with no trigger describes the root or a group instead of a leaf command:
slash command mod: description: Moderation tools enabled for: manage server slash command settings color: description: Colour settings slash command settings color set <color: color>: description: Set the colour trigger: reply with hidden "Colour %{_color}%"
settings color groups settings color set under /settings color. Without a root descriptor, the root inherits its permissions from the intersection of its subcommands. Declaring the same root in two different scripts merges too, but logs a warning; keep one script per root.
Inside the trigger
Value | Holds |
|---|---|
| a named argument's value, as declared in the header |
| the same argument, by position |
| the first argument whose type is |
| the full path that ran, e.g. |
| the invocation's context |
reply with hidden answers only the user who ran the command; defer the interaction acknowledges it early when the trigger is slow, before Discord's own 3-second timeout. See Slash options for argument types, choices and autocomplete.
Pushing to Discord
update the discord commands (all structured application commands) in event-guild from on guild ready pushes every structure-declared command to that guild; the global variant reads update the discord commands {_ping} globally in event-bot from on ready. A reload never touches Discord by itself. See Registering commands for register, unregister and the global/guild timing.
[the] structured (slash|:user|:message) command[s] %strings%The commands declared by 'slash command' / 'user command' / 'message command' structures, as command objects ready to be pushed: every 'slash command mod ...' structure is merged into one '/mod' command.Errors you may see
Message (console) | Cause | Fix |
|---|---|---|
'x' is not a valid slash command name (lowercase, 1 to 32 letters, digits, - or _) | a path word breaks Discord's naming rules | use lowercase letters, digits, |
A slash command argument needs a name: <user> should be <name: user> | an argument in the header has no | write |
A slash command argument cannot have a default value |
| make the argument optional ( |
A required argument cannot follow an optional one in a slash command | a required | move required arguments first |
The slash command has arguments but no trigger | arguments are declared but | add a |