Context
Context
Represents the execution context for a command, providing access to Discord.js objects, command metadata, and various utility methods for command execution.
class Context<ExecutionMode extends CommandExecutionMode = CommandExecutionMode, Args extends Record<string, any> = Record<string, any>> {
public readonly interaction: ContextParameters<ExecutionMode>['interaction'];
public readonly message: ContextParameters<ExecutionMode>['message'];
public readonly guild!: Guild | null;
public readonly guildId!: string | null;
public readonly channel!: TextBasedChannel | null;
public readonly channelId!: string | null;
public readonly client: Client;
public readonly command: LoadedCommand;
constructor(commandkit: CommandKit, config: ContextParameters<ExecutionMode, Args>)
store: void
commandName: string
invokedCommandName: string
options: CommandContextOptions<ExecutionMode>
forwarded: boolean
forwardCommand(command: C) => Promise<never>;
executionMode: ExecutionMode
isInteraction() => this is InteractionCommandContext;
isChatInputCommand() => this is ChatInputCommandContext;
isAutocomplete() => this is AutocompleteCommandContext;
isMessageContextMenu() => this is MessageContextMenuCommandContext;
isUserContextMenu() => this is UserContextMenuCommandContext;
isMessage() => this is Context<'message'>;
getCommandIdentifier() => string;
getGuildLocale() => Locale | null;
getUserLocale() => Locale | null;
getLocale(preferUser: = false) => Locale;
setLocale(locale: Locale | null) => void;
clone(config?: Partial<ContextParameters<ExecutionMode>>) => Context<ExecutionMode>;
isMiddleware() => this is MiddlewareContext<ExecutionMode>;
args() => string[];
}
interaction
ContextParameters<ExecutionMode>['interaction']The interaction that triggered the command.
message
ContextParameters<ExecutionMode>['message']The message that triggered the command.
guild
Guild | nullThe guild where the command was triggered.
guildId
string | nullThe guild ID where the command was triggered.
channel
TextBasedChannel | nullThe channel where the command was triggered.
channelId
string | nullThe channel id where the command was triggered.
client
ClientThe client instance.
command
The command that this context belongs to.
constructor
(commandkit: CommandKit, config: ContextParameters<ExecutionMode, Args>) => ContextCreates a new command context.
store
The shared key-value store for this context. This can be used to store data that needs to be shared between middlewares or commands. This store is shared across all contexts in the same command execution, including the cloned contexts and middleware contexts.
commandName
stringGets the name of the current command.
invokedCommandName
stringGets the invoked command name (could be an alias for message commands)
options
CommandContextOptions<ExecutionMode>Gets the command options based on the execution mode.
forwarded
booleanWhether this context was forwarded from another context. This happens when a command forwards its context to another command.
forwardCommand
(command: C) => Promise<never>Forwards the context to another command. The target handler will be the same as current handler.
executionMode
ExecutionModeThe execution mode of the command.
isInteraction
() => this is InteractionCommandContextWhether the command was triggered by an interaction.
isChatInputCommand
() => this is ChatInputCommandContextWhether the command was triggered by a slash command interaction.
isAutocomplete
() => this is AutocompleteCommandContextWhether the command was triggered by an autocomplete interaction.
isMessageContextMenu
() => this is MessageContextMenuCommandContextWhether the command was triggered by a message context menu interaction.
isUserContextMenu
() => this is UserContextMenuCommandContextWhether the command was triggered by a user context menu interaction.
isMessage
() => this is Context<'message'>Whether the command was triggered by a message.
getCommandIdentifier
() => stringReturns the command identifier.
getGuildLocale
() => Locale | nullReturns the locale of the guild where this command was triggered.
getUserLocale
() => Locale | nullReturns the locale of the user who triggered this command.
getLocale
(preferUser: = false) => LocaleReturns the locale for this command.
setLocale
(locale: Locale | null) => voidSets the locale for this command.
clone
(config?: Partial<ContextParameters<ExecutionMode>>) => Context<ExecutionMode>Creates a clone of this context
isMiddleware
() => this is MiddlewareContext<ExecutionMode>Checks if this context is a middleware context.
args
() => string[]Gets the command arguments (only available for message commands).