Command
function in meocord/decorator Since 4.0.0
Command<
CBC extends BuildableCommandType,
T extends CommandBuilderConstructor<CBC> | CommandType,
N extends string | Route = string,
>(
name: N,
builderOrType: T,
): <P extends Record<string, any>, R>(
target: object,
propertyKey: string,
_descriptor: (
| TypedPropertyDescriptor<
Handles<CommandInteractionType<CBC, T>, [params: P], R>
>
| TypedPropertyDescriptor<Handles<CommandInteractionType<CBC, T>, [], R>>
| TypedPropertyDescriptor<() => R>
) &
RouteAccepts<N, T, P> &
TypedParamsAccept<N, T, P> &
ChoicesAccept<N, T, P>,
) => voidRoutes a command, a component or a modal submission to the method it decorates.
Use it for each interaction a controller handles: a slash or context menu command by its name or
subcommand path, and a button, select menu or modal by its customId pattern or a route(). For an
option's suggestions, use Autocomplete; for a message command, @MessageHandler.
Where it runs
- The handler — after every stage the call passed
Parameters
| Name | Type | Since | Description |
|---|---|---|---|
name | N | 4.1.0 | The command's name or subcommand path, or a component's customId pattern or route. |
builderOrType | T | A command builder class, which registers the command with Discord, or a
|
Returns
Returns a method decorator.
<P extends Record<string, any>, R>(
target: object,
propertyKey: string,
_descriptor: (
| TypedPropertyDescriptor<
Handles<CommandInteractionType<CBC, T>, [params: P], R>
>
| TypedPropertyDescriptor<Handles<CommandInteractionType<CBC, T>, [], R>>
| TypedPropertyDescriptor<() => R>
) &
RouteAccepts<N, T, P> &
TypedParamsAccept<N, T, P> &
ChoicesAccept<N, T, P>,
) => voidThrows
Error when the builder throws as it is made or as it builds, naming the handler, the builder and the command, and on a subcommand path saying the builder of the path's command describes it; and, as the decorator applies, when the method has no implementation, the builder is not a
@CommandBuilder, a context menu handler declares the other kind than its builder registers, or a customId pattern cannot be read.
Examples
@Command('help', CommandType.SLASH)
async help(interaction: ChatInputCommandInteraction) {
await respond(interaction).send('Here is how to use me.')
}
@Command('stats/{id}', CommandType.BUTTON)
async stats(interaction: ButtonInteraction, { id }: { id: string }) {
await respond(interaction).send(`Stats for ${id}.`)
}