Expand description
The interaction router (D-251–D-255): handlers registered by command name or by component
and modal custom_id, next to Events::InteractionCreate.
| Registration | Interactions | Handler argument |
|---|---|---|
Client::command | commands (slash and context menu) | CommandInteraction |
Client::autocomplete | autocomplete of a command’s options | AutocompleteInteraction |
Client::component | buttons and select menus | ComponentInteraction |
Client::modal | modal submissions | ModalInteraction |
- Commands are routed by their full name as Discord shows it (D-253):
"ping","mod ban","mod config set", or the name of a context menu command ("Report Message"). A route for"mod"(or"mod config") catches the subcommands that have no route of their own. Slash and context menu commands sharing a name share the route; the handler can tell them apart bykind. - Components and modals are routed by the part of their
custom_idbefore the first:(D-254): the route"vote"receivesvoteandvote:42, andargsreturns42. - Routes only route (D-255): commands are registered with Discord through
ctx.commands(), andEvents::InteractionCreateis still emitted for every interaction, routed or not.
Every wrapper holds the event’s Arc (no copy), dereferences to the typed data and
implements InteractionExt, so cmd.get_string("reason")
and cmd.reply(&ctx, …) both work.
discord.js has no router: its counterpart is a switch on interaction.commandName in the
interactionCreate listener.
Structs§
- Autocomplete
Interaction - An autocomplete interaction given to a
Client::autocompleteroute (D-252): dereferences to theCommandData(focused_value,get_string, …) and answers withrespond. - Command
Interaction - A command interaction given to a
Client::commandroute (D-252): dereferences to theCommandData(get_string,subcommand, …) and answers throughInteractionExt(reply,defer_reply, …). - Component
Interaction - A component interaction given to a
Client::componentroute (D-252): dereferences to theComponentData(custom_id,values,users, …), with theargsof its custom ID, and answers throughInteractionExt(update,reply,show_modal, …). - Modal
Interaction - A modal-submit interaction given to a
Client::modalroute (D-252): dereferences to theModalSubmitData(text_value,selected_users, …), with theargsof its custom ID, and answers throughInteractionExt.