Work In Progress
This documentation is in beta. It's missing lots of content, search is broken, and many links go nowhere. These problems will be fixed before release, but there's plenty of work left!
Skip to main content

Basic Command APIs

All application command types extend the ApplicationCommand type, which provides some basic common APIs. These APIs are available regardless of command type, so you should familiarise yourself with them!

The ApplicationCommand type extends the base Command type, so it inherits the APIs defined there. For more information on the APIs common to all commands, see the basic command API page.

abstract class ApplicationCommand : Command

Abstract base type representing everything that all application commands have in common.

Type Parameters
EType: InteractionCreateEvent

Base type representing the events that can trigger application command invocations.

Constructor Arguments
val extensionType: Extension

The extension that registered this command.

Builders

check { ... }Receiver: CheckContext<E>

Register a check, which must pass for the command to execute when invoked.

Functions

open guild(...)

Provide a guild ID to register this command against, or null to override any previously-set guild.

By default, all application commands are global. This can be changed in your bot's application command builder, by calling the defaultGuild() function.

open requirePermission(...)

Provide one or more default required permissions that users must have to be able to run this command.

Note: Kord Extensions doesn't enforce the permissions you specify here. This is because server staff on Discord can change the permissions required to execute a command.

If you need to limit command usage to a specific role or set of permissions, consider also writing a check when you set this. If you write a check, you should also set this property - it'll hide the command on Discord!

Show/Hide Internal APIs
abstract suspend call(...)

Command logic function implemented by the application command sub-types, and called via the doCall function.

This function is responsible for a command's logical flow. It should run the command's defined checks, respond to the Discord interaction, create the correct command context object, and ultimately execute your command's action {} body.

Arguments
eventType: E

Event triggering this command execution.

cacheType: MutableMap<String, Any>

Map representing a data cache shared with the command's registered checks, and made available in the command context.

open suspend doCall(...)

Attempt to execute this command based on the provided event object. This function creates a cache map, and passes it to the call function along with the event object.

This is normally called by the ApplicationCommandRegistry when someone invokes an application command on Discord.

open suspend localise(...)Returns:Localised<String>

Translates the given translation key object into your bot's default locale, and all configured application command locales, lower-casing it if required.

This is used by the ApplicationCommandRegistry to figure out what names and descriptions your commands should use in each configured locale, and it's also called by the localisedName lazy property when first accessed.

Arguments
keyType: Key

Translation key to localise.

lowerCaseType: BooleanDefault: false

Whether the resulting strings should be lower-cased.

This is generally only used when translating slash command names, which must always be lower-case.

open suspend runChecks(...)Returns:Boolean

By default, this function simply returns the result of the runStandardChecks() function, but it can be overridden if command types need to extend this behaviour.

open suspend runStandardChecks(...)Returns:Boolean

Runs the checks defined in checkList (via the check builders and functions), throwing and interrupting command execution if needed.

Properties

var allowByDefaultType: Boolean

We recommend using the allow...() functions defined on each command type instead of manually setting this property, to keep things simple.

Whether to allow everyone on a guild to use this command by default. This property is represented by a set of getters and setters, and has no backing field of its own.

Setting this to true will set defaultMemberPermissions to null automatically. Setting it to false will set defaultMemberPermissions to an empty Permissions object instead.

This property will return true if defaultMemberPermissions is null.

var allowInDmsType: BooleanDefault: extension.allowApplicationCommandInDMs

Whether this command should be allowed in DMs.

This will always return false if your command is restricted to a specific guild, regardless of what you set it to.

var defaultMemberPermissionsType: Permissions?Default: null

We recommend using the requirePermission() function instead of manually setting this property, to keep things simple.

The permissions a guild member must have to be able to execute this command, by default.

Note: Kord Extensions doesn't enforce the permissions you specify here. This is because server staff on Discord can change the permissions required to execute a command.

If you need to limit command usage to a specific role or set of permissions, consider also writing a check when you set this. If you write a check, you should also set this property - it'll hide the command on Discord!

Show/Hide Internal APIs
protected val botType: ExtensibleBot

Quick access to your bot's ExtensibleBot object.

open val checkListType: MutableList<CheckWithCache<E>>Default: mutableListOf()

List of this command's registered checks.

open var guildIdType: Snowflake?Default: settings.applicationCommands.defaultGuild

Guild ID to register this command against. Usually set via the guild() function.

open var localisedNameType: Localised<String>Default: localise(name, this is SlashCommand)

This function's localised name, calculated lazily when accessed. Slash commands always have lower-cased names.

val registryType: ApplicationCommandRegistry

Quick access to your bot's application command registry.

abstract val typeType: dev.kord.common.entity.ApplicationCommandType

This command object's Discord command type. Overridden by each type of application command, and used during registration.