Skip to main content
Commands extend Command and use decorators to describe the application command Discord should register.

Create a Chat Input Command

Place the class in the command directory passed to client.load(). The loader discovers the class and adds its builder to the application-command registry.

Add Subcommands

Use @RegisterSubcommand on methods that should receive a specific subcommand:
Subcommand groups, user context-menu commands, message context-menu commands, and guild restrictions use the matching registration decorators exposed by the package.

Restrict Who Can Run a Command

Preconditions are checks that run before a command. Write one as a piece that extends Precondition in the preconditions directory:
Then list it by name in the preconditions option of the command:
When a precondition denies the interaction, the framework skips the command and emits chatInputCommandDenied with the error. Reply to the user from a listener on that event. See Preconditions for AND/OR combinations, parallel runs, global preconditions, and interaction handlers.

Publish Command Definitions

To keep Discord in sync automatically, enable startup registration on the Client. After listen() runs its postListen hooks, the client compares the loaded commands with the deployed ones and writes only the differences:
Deployed commands the bot no longer defines are kept unless you set removeUnknown: true. If registration fails, the client logs a warning and keeps serving interactions. In sharder or broker deployments, use when to register from one process only. Bots that use client.fetch() instead of listen() call await client.registry.sync() after client.load(). See Sync commands on startup for every option. To overwrite whole scopes instead, push the registry to Discord after loading pieces:
Global command changes can take time to propagate. Use guild-restricted commands while iterating when you need changes to appear immediately.

Test Before Publishing

The testing package can run the same command class against a local interaction fixture without contacting Discord. See Testing interactions for a complete example.