Command Internals
The commands system is made up of several components that work together to store, resolve, execute commands and more.
Command system components
Specifically, these components are:
CommandManager: The entry point for the command system, holding all the command-related objects and methods that use all of these objects. All objects below are contained here.CommandResolver: Resolves the command that a given command interaction refers to.CommandExecutor: Executes commands, checking itsMiddlewareListand passing errors to theErrorHandler.CommandRepository: Stores all the currently registered commands.CommandCustomIdCodec: De/serializes commands names to/from customId strings, for the Command Components feature.CommandDeployer: Deploys commands to Discord and stores the ApplicationCommand mappings.Command EventBus: AnEventBusthat emits command related events.CommandSubscriptionsContainer: Stores the subscribers that are subscribed to the client'sEventBusto listen for command interactions.
Execution Sequence
The following diagrams show the flow of a command execution. You can check the guide of each component to see exactly how it works, or how to replace it.
Diagram usage
- You can zoom and drag on the diagrams.
- A dashed step means it's executed through a non awaited (but caught) Promise, so the next one is inmediately executed if there's an I/O operation in the step.
- You can hover over steps with
(?)to see extra details. - If a step goes to a target, and that target doesn't continue the flow, then it's an immediate return, like a getter call.
Command event
For a command to be executed, you first receive a interactionCreate event, which is then passed to the CommandManager:
Command resolution
The CommandResolver then resolves the command that the interaction refers to. For component interactions, this first needs an intermediate step through the CommandCustomIdCodec to deserialize the customId.
Command Interactions
Component Interactions
Command execution
Once the command is resolved, it's passed to the CommandExecutor:
On which the execution ends.
Next, see the documentation of each component, where you'll find what it does and how to replace it.
Last updated on
