MiddlewareContext
MiddlewareContext extends Context<T>
new MiddlewareContext(commandkit, config)
Parameter | Type | Optional | Description |
---|---|---|---|
commandkit | CommandKit | ❌ | The command kit instance. |
config | ContextParameters<T> | ❌ | The context parameters. |
Properties
public client: any
The client instance.
public commandkit: any
The command kit instance.
public interaction: any
The interaction that triggered the command.
public message: any
The message that triggered the command.
public cancelled: any
Whether the command execution was cancelled.
public commandName: any
public executionMode: any
The execution mode of the command.
public forwarded: any
Whether this context was forwarded from another context. This happens when a command forwards its context to another command.
public options: any
public store: any
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.
Methods
public args(): Array<string>
public cancel(): void
Cancels the command execution.
public cancelDeferred(id): void
Cancels the deferred function with the given identifier.
Parameter | Type | Optional | Description |
---|---|---|---|
id | string | ❌ | The identifier of the deferred function. |
public clone(config?): Context<T>
Creates a clone of this context
Parameter | Type | Optional |
---|---|---|
config | Partial<ContextParameters<T>> | ✅ |
public defer(fn): string
Defers the given function to be executed after this command's execution.
Parameter | Type | Optional | Description |
---|---|---|---|
fn | GenericFunction<[ | CommandKitEnvironment | ]> |
public exit(): void
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.
public forwardCommand(command): Promise<never>
Forwards the context to another command. The target handler will be the same as current handler.
Parameter | Type | Optional | Description |
---|---|---|---|
command | string | ❌ | The command to forward to. |
public getCommandIdentifier(): string
Returns the command identifier.
public getGuildLocale(): null | Locale
Returns the locale of the guild where this command was triggered.
public getLocale(preferUser): Locale
Returns the locale for this command.
Parameter | Type | Optional | Description |
---|---|---|---|
preferUser | boolean | ❌ | Whether to prefer the user's locale over the guild's locale. |
public getUserLocale(): null | Locale
Returns the locale of the user who triggered this command.
public isAutocomplete(): is | AutocompleteCommandContext
Whether the command was triggered by an autocomplete interaction.
public isCached(fn): boolean
Validates if the given function is a cached function.
Parameter | Type | Optional | Description |
---|---|---|---|
fn | GenericFunction | ❌ | The function to validate. |
public isInteraction(): is | InteractionCommandContext
Whether the command was triggered by an interaction.
public isMessage(): is | Context<'message'>
Whether the command was triggered by a message.
public isMessageContextMenu(): is | MessageContextMenuCommandContext
Whether the command was triggered by a message context menu interaction.
public isMiddleware(): is | MiddlewareContext<T>
public isSlashCommand(): is | SlashCommandContext
Whether the command was triggered by a slash command interaction.
public isUserContextMenu(): is | UserContextMenuCommandContext
Whether the command was triggered by a user context menu interaction.
public locale(locale?): Localization
Returns the i18n api for this command.
Parameter | Type | Optional | Description |
---|---|---|---|
locale | Locale | ✅ | The locale to use for the i18n api. |
public setLocale(locale): void
Sets the locale for this command.
Parameter | Type | Optional | Description |
---|---|---|---|
locale | null | Locale | ❌ |