Chat Commands
Please don't skip over the above admonitions — they're important!
Introduction
Chat commands are a fairly simple concept. When a user sends a message starting with a command prefix (or bot mention), the command name and arguments, Kord Extensions can process it accordingly.
All builder functions should be called within your bot'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.
Chat commands support command arguments, which are specified as explained on the commands overview page. However, unlike the other command types, they do not support Modals.
As Discord recommends against using chat commands, they must be enabled before they can be used. For more information, see the configuration documentation.
Extension API
The following APIs are available on the Extension
type, which you can use to define your chat commands and modify their behavior.
Builders
Name | Receiver | Description |
---|---|---|
|
| Register a check that must pass for the |
|
| Register a standalone chat command. This builder function optionally takes the constructor of an arguments class as the first argument, representing this command's arguments to be supplied on Discord. |
|
| Register a grouped chat command. This builder function optionally takes the constructor of an arguments class as the first argument, representing this command's arguments to be supplied on Discord. |
Standalone Commands
Standalone commands are the simplest type of chat command, and they're defined using the chatCommand
builder function. This builder is a receiver function against the ChatCommand
type, which provides a number of APIs that can be used to configure your command and its metadata.
At minimum, a command must have a name
, description
and action
defined.
The following APIs are available for use when writing a chat command, in addition to those provided by the base Command
type.
Builders
Name | Receiver | Description |
---|---|---|
Required Builders | ||
|
| Required: Register the command's action, which will be run when the command is invoked. |
Optional Builders | ||
|
| Register a check that must pass for the command's |
Properties
Name | Type | Description | |
---|---|---|---|
Required Properties | |||
|
| Required: Key object representing the command's description. This should explain what the command does. If the string spans multiple lines, the first line should be a short summary of what the command does, with a blank line underneath. | |
|
| Required: Key object representing the command's name, which is used to identify the command internally and for invoking the command on Discord. | |
Optional Properties | |||
|
| Key object representing a comma-separated list of alternative names that may be used to invoke this command. If an alias conflicts with the name of another command, the other command will take priority. | |
|
| Whether to allow the parser to parse arguments in the form of | |
|
| Whether this command is currently enabled, which can be changed at runtime if needed. When disabled, a command can't be invoked and won't be shown in help commands. Defaults to | |
|
| Whether this command should be hidden from help command listings. Hidden commands may still be invoked. Defaults to | |
|
| By default, translated command names may be invoked based on the bot's configured locale resolvers. By setting this property to | |
Translation-Related Properties | |||
|
| Translation key referencing a comma-separated list of alternative command names. If this property is set, the | |
|
| Key object representing the command signature to be shown in help commands. By default, Kord Extensions will generate a signature automatically. This property may be set if you wish to override it. Command signatures should not include the command name. Example signature: |
Grouped Commands
Grouped commands are a special type of chat command that contains subcommands. They work just like a standalone chat command, but with the addition of a set of functions that allow you to nest other commands within them. They're defined using the chatGroupCommand
builder function.
To execute a grouped command, you provide the command prefix, name and arguments the same way you do with a standalone command. However, the first argument provided to the grouped command will be matched against the names of any nested commands, and removed from the list of arguments provided to the found command.
Grouped commands may contain subcommands or nested grouped commands. There is no limit on how deep you may nest grouped commands, but we recommend you avoid nesting them more than once, for the sake of clarity and ease of use.
The grouped command's action
is executed when the command is executed without any arguments, or when none of the nested commands match the first argument provided to it. A default action
block is provided, which shows help information about the command and its nested commands. However, you may provide your own if needed or desirable.
The following APIs are available for use when writing a grouped chat command, in addition to those provided by the base ChatCommand
type..
Builders
Name | Description |
---|---|
| Define a subcommand. This builder function mirrors the behavior of the |
| Define a grouped subcommand. This builder function allows you to nest grouped commands as deeply as is required. It mirrors the behavior of the |
Command Context
The ChatCommandContext
type is the receiver for all chat command action
blocks. This type provides relevant APIs on top of the base command context object type, allowing you to efficiently respond to command invocations.
The following additional APIs are provided:
Builders
Name | Receiver | Description |
---|---|---|
|
| Convenience function, allowing you to easily create a button-based paginator. The following parameters are supported:
Note: This will not send the paginator automatically. You'll need to call the For more information on paginators (and the paginator builder), see the dedicated documentation. |
Functions
Name | Parameters | Description |
---|---|---|
| Generate and send help information for this command. Returns | |
Translation-Related Functions | ||
|
| Convenience function that allows you to respond to a message with translated content, using the resolved locale for this command context. This makes use of the Overloads are provided which support both ordinal and named placeholders. For more information, see the dedicated documentation. |
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 |
Data Properties | ||
|
| Object representing the channel this command was invoked within. |
|
| Object representing the guild this command was invoked within, or |
|
| Object representing the member that executed this command, or |
|
| Object representing the message that invoked this command. |
|
| Object representing the user that executed this command, or |