registerCommands
The registerCommands function is a utility used to deploy your application commands (Slash Commands and Context Menus) to Discord. It automatically handles the distinction between global commands and guild-specific commands based on the handler configuration.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
| token? | string | Your Discord bot token. |
| applicationId? | string | Your Discord application ID. |
| …handlers | FlatOrNestedArray<AnyHandler> | Rest parameter containing individual handlers or arrays of handlers. |
Behavior
Section titled “Behavior”- Internal Filtering: The function automatically extracts handlers with a
handlerTypeofslashorcontext. Other handler types are ignored during registration. - Global vs Guild:
- If a command is marked as a guild command (via
guildIds), it will be registered specifically to those guilds usingbulkOverwriteGuildCommands. - Otherwise, it is registered globally via
bulkOverwriteGlobalCommands.
- If a command is marked as a guild command (via
- Validation: If
tokenorapplicationIdis missing, the function logs a warning and skips registration. These can beundefinedbecause your types may be not working.
Example
Section titled “Example”import { registerCommands } from "honocord";import { myCommands } from "./commands";
await registerCommands(process.env.DISCORD_TOKEN, process.env.APPLICATION_ID, ...myCommands);