Skip to main content
Version: Next

MiddlewareContext

MiddlewareContext extends Context<T, MiddlewareContextArgs>

new MiddlewareContext(commandkit, config)
ParameterTypeOptionalDescription
commandkitCommandKitThe command kit instance.
configContextParameters<T, MiddlewareContextArgs>The context parameters.

Properties

public channel: any

The channel where the command was triggered.

public channelId: any

The channel id where the command was triggered.

public client: any

The client instance.

public command: any

The command that this context belongs to.

public commandkit: any

The command kit instance.

public config: any

The context parameters.

public guild: any

The guild where the command was triggered.

public guildId: any

The guild ID where the command was triggered.

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 clone(config?): Context<T>

Creates a clone of this context

ParameterTypeOptional
configPartial<ContextParameters<T>>

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.

ParameterTypeOptionalDescription
commandCThe 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.

ParameterTypeOptionalDescription
preferUserbooleanWhether 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 isChatInputCommand(): is | ChatInputCommandContext

Whether the command was triggered by a slash command interaction.

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 isUserContextMenu(): is | UserContextMenuCommandContext

Whether the command was triggered by a user context menu interaction.

public setCommandRunner(fn): void

Sets command runner function to wrap the command execution.

ctx.setCommandRunner(async (execute) => {
// do something before command execution
await execute();
// do something after command execution
})
ParameterTypeOptionalDescription
fnRunCommandThe function to set.

public setLocale(locale): void

Sets the locale for this command.

ParameterTypeOptionalDescription
localenullLocale