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 Context APIs

All command contexts extend the CommandContext type, which provides some basic common APIs. These APIs are available in the action { } block regardless of command type, so you should familiarise yourself with them!

abstract class CommandContext : KordExKoinComponent, TranslatableContext

Abstract base type representing an execution context common to all commands.

Constructor Arguments
open val commandType: Command

Object representing the currently executing command.

Command context implementations tend to have a property with a more specific type than this.

open val eventObjType: Event

The event that triggered this command execution.

Command context implementations tend to have a property with a more specific type than this.

open val commandNameType: Key

Translation key representing the command's name, as provided by the user and then lower-cased.

As some command types support aliases, this generally doesn't match command.name. When working with chat commands, consider using commandName.key to represent the command name in your responses.

open val cacheType: MutableStringKeyedMap<Any>

Data cache shared with the command's defined checks.

Functions

Show/Hide Internal APIs
abstract getChannel(...)Returns:ChannelBehavior

Retrieve the relevant channel for this command execution.

You should generally use the context's corresponding property instead, as this function doesn't do any caching.

abstract getGuild(...)Returns:GuildBehavior?

Retrieve the relevant guild for this command execution, if any.

You should generally use the context's corresponding property instead, as this function doesn't do any caching.

abstract getMember(...)Returns:MemberBehavior?

Retrieve the relevant guild member for this command execution, if any.

You should generally use the context's corresponding property instead, as this function doesn't do any caching.

abstract getUser(...)Returns:UserBehavior?

Retrieve the relevant user for this command execution, if any.

You should generally use the context's corresponding property instead, as this function doesn't do any caching.

abstract populate(...)

Populate any relevant data required by a specific command context subtype.

Properties

open val cacheType: MutableStringKeyedMap<Any>

Data cache shared with the command's defined checks.

open val commandType: Command

Object representing the currently executing command.

Command context implementations tend to have a property with a more specific type than this.

open val commandNameType: Key

Translation key representing the command's name, as provided by the user and then lower-cased.

As some command types support aliases, this generally doesn't match command.name. When working with chat commands, consider using commandName.key to represent the command name in your responses.

open val eventObjType: Event

The event that triggered this command execution.

Command context implementations tend to have a property with a more specific type than this.

val sentryType: SentryAdapter