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
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[];
exit() => never;
}
interaction
ContextParameters<ExecutionMode>['interaction']
The interaction that triggered the command.
message
ContextParameters<ExecutionMode>['message']
The message that triggered the command.
guild
Guild | null
The guild where the command was triggered.
guildId
string | null
The guild ID where the command was triggered.
channel
TextBasedChannel | null
The channel where the command was triggered.
channelId
string | null
The channel id where the command was triggered.
client
Client
The client instance.
command
The command that this context belongs to.
constructor
(commandkit: CommandKit, config: ContextParameters<ExecutionMode, Args>) => Context
Creates 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
string
Gets the name of the current command.
options
CommandContextOptions<ExecutionMode>
Gets the command options based on the execution mode.
forwarded
boolean
Whether 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
ExecutionMode
The execution mode of the command.
isInteraction
() => this is InteractionCommandContext
Whether the command was triggered by an interaction.
isChatInputCommand
() => this is ChatInputCommandContext
Whether the command was triggered by a slash command interaction.
isAutocomplete
() => this is AutocompleteCommandContext
Whether the command was triggered by an autocomplete interaction.
isMessageContextMenu
() => this is MessageContextMenuCommandContext
Whether the command was triggered by a message context menu interaction.
isUserContextMenu
() => this is UserContextMenuCommandContext
Whether the command was triggered by a user context menu interaction.
isMessage
() => this is Context<'message'>
Whether the command was triggered by a message.
getCommandIdentifier
() => string
Returns the command identifier.
getGuildLocale
() => Locale | null
Returns the locale of the guild where this command was triggered.
getUserLocale
() => Locale | null
Returns the locale of the user who triggered this command.
getLocale
(preferUser: = false) => Locale
Returns the locale for this command.
setLocale
(locale: Locale | null) => void
Sets 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).
exit
() => never
Stops upcoming middleware or current command execution. If this is called inside pre-stage middleware, the next run will be the actual command, skipping all other pre-stage middlewares. If this is called inside a command itself, it will skip all post-stage middlewares. If this is called inside post-stage middleware, it will skip all other post-stage middlewares.