Commands
Context and pipeline
What a handler receives, what runs before it, and what happens when it throws.
The context
The handler receives a CommandContext.
| Member | Role |
|---|---|
ctx.message | The triggering Message. |
ctx.author | Its author. |
ctx.args | The parsed arguments, typed from the builder. |
ctx.reply(content) | Answers where the command was triggered. Takes a string or a MessageBuilder. |
ctx.replyDM(content) | Answers in a DM. Rejects when a channel author cannot be verified. |
ctx.can(permission) | Whether the author holds a permission. |
ctx.canManageRole(role) | Whether the author ranks above that role. |
ctx.canManageContact(c) | Whether the author ranks above that contact. |
The pipeline
Every message that matches the trigger rule goes through these steps in order.
- Trigger. Does it match a registered name or alias?
- Scope. Is the command allowed in this DM or channel?
- Age. Is a backlog message too old?
- Permissions. Does the author hold every required permission?
- Cooldown. Did the author run this command too recently?
- Arguments. Do the values match the declaration?
- Handler.
Every refusal emits commandDenied with a typed DenyReason. Scope and age refusals are silent. The
others answer with a text from client.replies.
When the handler throws
The client emits commandError and answers with client.replies.internalError. The error's detail never
goes on the air. setErrorHandler() replaces that reply for one command.