Slash Commands
Slash commands are a form of application command, triggered by users by typing a slash (/
) followed by the command's name and arguments, and sending it via Discord's message input box.
When registered by your bot, slash commands are visible in a menu displayed above Discord's message input box when a user types a slash (/
) into it. This menu allows users to browse a list of all available slash commands, and provides access to their descriptions and arguments.
All builder functions should be called within your extension's setup
function when you're registering commands before the bot starts up. However, it is also possible to register commands later on in the bot's lifecycle by calling the same functions.
Extension API
The following APIs are available on the Extension
type, which you can use to define your slash commands and modify their behavior.
Builders
Name | Receiver | Description |
---|---|---|
Checks | ||
|
| Register a check that must pass for the |
Commands | ||
|
| Register an ephemeral slash command. This builder function optionally takes the constructor of an arguments class, the constructor of a modal form class, or both. |
|
| Register a public slash command. This builder function optionally takes the constructor of an arguments class, the constructor of a modal form class, or both. |
Standalone Commands
Standalone commands are the simplest type of slash command, and they're defined using the builder function corresponding with the intended interaction response type:
ephemeralSlashCommand
for slash commands that respond ephemerally.publicSlashCommand
for slash commands that respond publicly.
Slash commands extend the ApplicationCommand
type, and provide some additional APIs. However, both ephemeral and public slash commands provide an identical API.
Builders
Name | Receiver | Description |
---|---|---|
Required Builders | ||
|
| Required: Register the command's action, which will be run when the command is invoked. If you provide the constructor for a modal form class to the registration function, it will be passed to this builder as the first argument. Note: If your command contains any subcommands or command groups, then you may not specify an |
Optional Builders | ||
|
| Register a check that must pass for this command's |
Nested Command Builders | ||
|
| Register a command group. This builder function takes the name of the command group as its first argument. Nested commands inherit the checks that are defined in their parent commands. |
|
| Register an ephemeral subcommand. Nested commands inherit the checks that are defined in their parent commands. |
|
| Register a public subcommand. Nested commands inherit the checks that are defined in their parent commands. |
Properties
Name | Type | Description | |
---|---|---|---|
Required Properties | |||
|
| Required: Key object representing the command's description, which should explain what the command does. The description may not be longer than 100 characters. | |
Other Properties | |||
|
| This command's parent slash command, if it's a subcommand. | |
|
| This command's parent command group, if it's a subcommand that's part of a group. |
Subcommands
Slash commands may contain subcommands, which allow you to create a tree of executable commands. Subcommands are executed by providing the name of the subcommand as an argument to its parent command. They may be registered by calling the relevant builder functions from within a standalone command or command group:
ephemeralSubCommand
for slash commands that respond ephemerally.publicSubCommand
for slash commands that respond publicly.
Subcommands have an identical API to standalone commands. Additionally, they inherit the checks defined in their parent commands.
Command Groups
Slash commands may contain command groups, which allow you to provide a nested group of subcommands. Grouped commands inherit the checks that are defined in the group's parent command.
Command groups are not executable on their own, acting only as containers for related subcommands. Because of this, they provide a much smaller set of APIs.
Builders
Name | Receiver | Description |
---|---|---|
|
| Register an ephemeral subcommand to this group. Grouped commands inherit the checks that are defined in the group's parent command. |
|
| Register a public subcommand to this group. Grouped commands inherit the checks that are defined in the group's parent command. |
Properties
Name | Type | Description | |
---|---|---|---|
Required Properties | |||
|
| Required: Key object representing the command group's description, which should explain what the group represents. The description may not be longer than 100 characters. Command group descriptions are not currently displayed in the Discord client, but the API still requires that you provide them. Discord has stated that they may be displayed someday, so it's a good idea to write proper descriptions regardless. | |
Other Properties | |||
|
| This group's parent slash command. |
Command Context
The SlashCommandContext
type is extended by types that match the intended interaction response type, and these types are used as the receiver for the relevant slash command action
blocks. This type provides relevant APIs on top of the base application command context object type, allowing you to efficiently respond to command invocations.
As mentioned in the base application command context documentation, all slash command context types inherit the relevant interaction context type.
The following additional APIs are provided:
Properties
Name | Type | Description |
---|---|---|
|
| The command's arguments, parsed into the arguments class you specified the constructor for when you registered this command. If you don't specify the aforementioned constructor, this will be an empty |