Skip to main content

Module router

Module router 

Source
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.

RegistrationInteractionsHandler argument
Client::commandcommands (slash and context menu)CommandInteraction
Client::autocompleteautocomplete of a command’s optionsAutocompleteInteraction
Client::componentbuttons and select menusComponentInteraction
Client::modalmodal submissionsModalInteraction
  • 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 by kind.
  • Components and modals are routed by the part of their custom_id before the first : (D-254): the route "vote" receives vote and vote:42, and args returns 42.
  • Routes only route (D-255): commands are registered with Discord through ctx.commands(), and Events::InteractionCreate is 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§

AutocompleteInteraction
An autocomplete interaction given to a Client::autocomplete route (D-252): dereferences to the CommandData (focused_value, get_string, …) and answers with respond.
CommandInteraction
A command interaction given to a Client::command route (D-252): dereferences to the CommandData (get_string, subcommand, …) and answers through InteractionExt (reply, defer_reply, …).
ComponentInteraction
A component interaction given to a Client::component route (D-252): dereferences to the ComponentData (custom_id, values, users, …), with the args of its custom ID, and answers through InteractionExt (update, reply, show_modal, …).
ModalInteraction
A modal-submit interaction given to a Client::modal route (D-252): dereferences to the ModalSubmitData (text_value, selected_users, …), with the args of its custom ID, and answers through InteractionExt.