Commands
Kord Extensions provides a rich, type-safe commands framework which is only as complex as you need it to be. At the moment, these basic types of commands are supported:
Chat Commands, prefix-based commands that are sent directly within messages on Discord.
Application Commands, which are based on Discord's interactions system and show up in the client's UI.
Context Commands, which are special commands that appear in right-click (or tap-and-hold) menus in the Discord client.
Slash Commands, which are invoked by typing a slash character (
/
) into the Discord chat input.
Each type of command has a specific set of use-cases and functionality, and thus provides a different API surface. However, all commands have quite a few things in common.
The following sections describe commands in generic terms. For more information on the specific types of supported commands (and how to use them), please see the pages linked above.
Arguments Classes
While Context Commands don't support command arguments, the other command types do. To specify your command's arguments, you'll need to create a class that extends the Arguments
type.
This class must make use of the available converter builder functions. Kord Extensions provides a large number of these, but it's possible to write your own or use those provided by third-party libraries.
See below for an example Arguments subclass.
Your argument class' constructor must then be provided to your command's builder function. The parsed arguments will be available via the arguments
property in your command's action
block.
The Arguments
type provides the following API properties:
Name | Type | Description |
---|---|---|
|
| When working with Slash Commands, your arguments may make use of Discord's autocomplete system. If you have later arguments with an autocompletion that requires the value of a previous argument, setting this to As some converter types provide a default |
For more information on the converter system (and the available argument types), see the dedicated documentation.
Modal Forms
A modal form is Kord Extensions' way of representing the settings and contents of a Discord modal. Chat commands don't support modals, but all other command types do.
If you want to make use of modals, you'll need to create a class that extends the `ModalForm` type. This class must make use of the provided input functions to define the modal's contents. It may also override the properties defined by the ModalForm
type.
Just like with command arguments, the constructor for your ModalForm
subtype must be passed to your command's builder function. When your command is executed, the modal is provided as an argument to your command's action
function.
For more information on the Modal system (and to get a few tips on how else to use it), see the dedicated documentation.
Command Objects
When you register a command, the builder function will return an object that extends the Command
type. This type provides generic access to basic command data and functionality.
The intended public API is described below. However, it's possible to extend this type (and the other command types) if you want to implement your own customized command types.
The Command
type extends the Lockable
and KordExKoinComponent
types. For more information on the other APIs provided by this type, we recommend examining it in your IDE.
Functions
Name | Arguments | Description |
---|---|---|
|
| If your bot requires any permissions to be able to execute the command, use this function to register those permissions. If the command is executed while the bot does not have the specified permissions, an error will be sent to the user, explaining which permissions the bot is missing. |
Properties
Mutable properties may be set in the builder function used to register your command.
Name | Type | Description |
---|---|---|
|
| The extension that this command belongs to. |
| Quick access to the bot's Kord instance. | |
|
| Whether to use a Mutex to prevent this command from being run concurrently with itself. Defaults to |
|
| Key object representing the command's name, which is used to invoke it. This property must be set for the command to be registered and has no default value. |
| Quick access to the bot's Sentry adapter. | |
| Quick access to the bot's translation provider. |
Context Objects
When a command is executed, the provided action
block is run. This block is a receiver function against a subtype of the CommandContext
type, which provides an API that allows you to work with the command's execution data and respond to the user.
The CommandContext
type extends the TranslatableContext
and KordExKoinComponent
types.
Functions
Name | Description |
---|---|
| Returns the relevant |
| Returns the relevant |
| Resolves and returns the relevant |
| Returns the relevant |
| Returns the relevant |
Properties
Name | Type | Description |
---|---|---|
|
| The cache object used for this execution, which may contain data set by the current command's defined Checks. |
|
| Quick access to the object representing the current command. No generic is used for this property, but subtypes will provide a separate property with a more concrete type. |
|
| Key object representing the command's name. For chat commands, this will be the name used to execute the command, which may be an alias. |
| The event object that caused this command execution. No generic is used for this property, but subtypes will provide a separate property with a more concrete type, generally named | |
| Quick access to the bot's Sentry context. | |
| Quick access to the bot's translations provider. |