Kord Extensions Help

Application Commands

Application commands are a special type of command that makes use of Discord's interaction system. Depending on the type, these commands are displayed in the Discord client in one of these ways:

  • Slash Commands: Above the chat input box when a user types a slash (/) character.

  • Message Commands: In a menu named "Apps" displayed when a user right-clicks or taps-and-holds on a message.

  • User Commands: In a menu named "Apps" displayed when a user right-clicks or taps-and-holds on a username or avatar.

Before diving into working with these command types, it's important to understand what Discord interactions are and how they work.

Application Command Objects

When you register an application command, the builder function will return an object that extends the ApplicationCommand type. This type extends the Command type, providing access to basic data and functionality specific to application commands.

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 ApplicationCommand type takes a generic type parameter based on the InteractionCreateEvent type, which is provided by the classes that extend ApplicationCommand. This generic type parameter will be referred to as E below.

The following API definitions do not include the APIs provided by any extended supertypes. For more information on the command API, see Command Objects.

Builders

Name

Receiver

Description

check

CheckWithCache <E>

Register a check that must pass for the command's action to be run, which is defined within the classes that extend ApplicationCommand. For more information on checks, see the dedicated documentation.

Functions

Name

Arguments

Description

guild

Snowflake?

Specify a specific guild to register this application command to. Guild-specific commands are only available in a single guild, and will not work in DMs with the bot. Provide null to clear the registration guild.

requirePermission

vararg Permission

Specify one or more permissions that a user must have before they may execute this command by default. Note: This setting is simply a default value that may be configured in the "Integrations" tab, within the guild's settings in the Discord client. It is not enforced by the command framework — use a check for that.

Properties

Name

Type

Description

Required Properties

🌐

name

String

Required: The command's name, which is used to invoke the command and is displayed on Discord. Your command's name must follow Discord's naming requirements.

Optional Properties

allowByDefault

Boolean

Whether to allow all members of a guild to execute this command by default. When set, this property will overwrite any permissions provided by the requirePermission function Returns true if no required permissions have been set using requirePermission.

allowInDms

Boolean

Whether to allow this command to be used in a DM with the bot. Always returns false if a registration guild has been set via the guild function, regardless of whether you modify this property's value yourself.

Application Command Context Objects

When an application command is executed, the provided action block is run. This block is a receiver function against a subtype of the ApplicationCommandContext type, which itself is a subtype of the CommandContext type. This type provides an API that allows you to work with the command's execution data and respond to the user.

Application command context objects always extend one of the interaction context types, unless you're using a command from the unsafe module.

The following API definitions do not include the APIs provided by any extended supertypes. For more information on the command API, see Context Objects.

Properties

Name

Type

Description

appPermissions

Permissions?

The permissions applicable to your bot in the current command execution context, as defined by the bot's roles and current channel permissions. Will be null if the command was executed in a DM with the bot.

genericCommand

ApplicationCommand <*>

Generic command object, representing the command this context belongs to. A more specific reference will be provided in this type's subtypes.

genericEvent

ApplicationCommandInteractionCreateEvent

Generic event object, representing the Discord event that triggered the current command execution. A more specific reference will be provided in this type's subtypes.

Last modified: 03 September 2024