Dynamic Commands
Handle application commands whose name isn't known ahead of time, using Honocord's dynamic handlers.
SlashCommandHandler and ContextCommandHandler require a fixed name set at load time. That works for commands your bot code defines up front, but not for commands whose name is only known at runtime — for example, per-guild custom commands stored in a database, where the application command is registered with Discord but Honocord has no matching named handler for it.
Honocord’s dynamic handlers catch exactly this case. They’re fallback handlers with no name of their own — instead of being looked up by name, one is invoked whenever an incoming application command interaction doesn’t match any registered SlashCommandHandler or ContextCommandHandler.
When They Fire
For every application command interaction, Honocord first checks the normal handler registry (global commands, then guild-specific commands by name). Only if nothing matches does it fall back to a dynamic handler.
Which dynamic handler runs depends on the interaction’s scope:
- Invoked in a guild (
guild_idpresent): the guild-scoped dynamic handler is tried first. If none is registered, Honocord falls back to the global-scoped one. - Invoked in a DM (no
guild_id): only the global-scoped dynamic handler is ever tried.
This mirrors the fact that Discord’s interaction payload doesn’t tell you whether a command was originally registered as guild- or global-scoped — only where it was invoked.
Note
The Four Classes
| Class | Catches |
|---|---|
DynamicGuildSlashCommandHandler | Unmatched chat input commands invoked in a guild |
DynamicGlobalSlashCommandHandler | Unmatched chat input commands invoked in a DM, or as fallback |
DynamicGuildContextCommandHandler | Unmatched User/Message context commands invoked in a guild |
DynamicGlobalContextCommandHandler | Unmatched User/Message context commands invoked in a DM, or as fallback |
Unlike SlashCommandHandler/ContextCommandHandler, these classes don’t extend a Discord builder — there’s no .setName() or .setDescription(), since the command is expected to be registered with Discord elsewhere (e.g. by your own admin flow that creates per-guild custom commands via the REST API directly).
Slash Commands
Autocomplete
Dynamic slash handlers support autocomplete the same way SlashCommandHandler does:
Context Menu Commands
A single dynamic context handler receives both User and Message context interactions — narrow with isOfType:
Global Fallback
Register a global dynamic handler to catch anything the guild-scoped one (or a DM invocation) doesn’t:
Loading
Load dynamic handlers like any other handler:
Tip