Kord Extensions Help

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.

publicSlashCommand(::MyArguments) { name = "my-command" description = "Description explaining command usage." check { hasPermission(Permission.MentionEveryone) } action { respond { // Note: Slash commands aren't actually able to mention // users in most cases content = "Hey, ${arguments.user.mention}! Get pinged!" } } }

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

slashCommandCheck

CheckWithCache <ChatInputCommandInteractionCreateEvent>

Register a check that must pass for the action belonging to all slash commands defined within this extension to be run. For more information on checks, see the dedicated documentation.

Commands

ephemeralSlashCommand

EphemeralSlashCommand

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.

publicSlashCommand

PublicSlashCommand

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

action

SlashCommandContext <Arguments>

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 action block. Slash commands containing nested commands are not executable on their own.

Optional Builders

check

CheckWithCache <ChatInputCommandInteractionCreateEvent>

Register a check that must pass for this command's action to be run. For more information on checks, see the dedicated documentation.

Nested Command Builders

group

SlashGroup

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.

ephemeralSubCommand

EphemeralSlashCommand

Register an ephemeral subcommand. Nested commands inherit the checks that are defined in their parent commands.

publicSubCommand

PublicSlashCommand

Register a public subcommand. Nested commands inherit the checks that are defined in their parent commands.

Properties

Name

Type

Description

Required Properties

🌐

description

String

Required: The command's description, which must be a string that explains what the command does. This string may not be longer than 100 characters.

Other Properties

parentCommand

SlashCommand?

This command's parent slash command, if it's a subcommand.

parentGroup

SlashGroup?

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

ephemeralSubCommand

EphemeralSlashCommand

Register an ephemeral subcommand to this group. Grouped commands inherit the checks that are defined in the group's parent command.

publicSubCommand

PublicSlashCommand

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

🌐

description

String

Required: The command group's description, which must be a string that explains what the group represents. This string 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

parentCommand

SlashCommand?

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

arguments

T: Arguments

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 Arguments object.

Last modified: 03 September 2024