Overview
Context types provide type-safe access to event data and response methods. All contexts includemsg, reply(), and edit() properties.
BaseContext
Base type for all event contexts.Properties
The event payload containing all event-specific data
Send a reply message
Edit the original message (for bot messages)
MessageContext
Context formessageCreate events.
Event Payload (msg)
The messageβs unique snowflake ID
The channel where the message was sent
The guild ID (undefined for DMs)
The message text content
The user who sent the message
Member data if sent in a guild
Example
InteractionContext
Context for slash command interactions.Event Payload (msg)
Unique interaction ID
Token for responding to the interaction
Name of the invoked command
User who invoked the command
Member data if invoked in a guild
Channel where command was invoked
Guild where command was invoked
Raw interaction data from Discord
Userβs locale (e.g., βen-USβ)
Guildβs preferred locale
Additional Property
Flattened command options as key-value pairs
Example
ComponentInteractionContext
Context for button clicks and select menu interactions.Event Payload (msg)
Unique interaction ID
Token for responding
User who clicked/selected
Component interaction data (includes
custom_id, values, etc.)ID of the message containing the component
Example
ModalSubmitContext
Context for modal (form) submissions.Event Payload (msg)
Unique interaction ID
Token for responding
User who submitted the modal
Modal submission data (includes field values)
Example
MessageUpdateContext
Context for message edit events.Event Payload (msg)
Message ID
Channel ID
New content (partial update)
ISO8601 timestamp of the edit
Previous message state (if cached)
New message state (if cached)
Example
MessageDeleteContext
Context for message deletion events.Event Payload (msg)
Deleted message ID
Channel ID
Guild ID
ReactionContext
Context for reaction add/remove events.Event Payload (msg)
User who added/removed the reaction
Message that was reacted to
Channel ID
Emoji object (includes name, id for custom emoji)
Whether itβs a super reaction
Example
CronContext
Context for scheduled cron jobs.Properties
The cron job name
ISO8601 timestamp when execution was scheduled
Example
Notes
- All contexts with
msgproperty follow theBaseContext<TPayload>pattern - Use type guards to safely access optional properties
- The
reply()method works for both messages and interactions - Interaction contexts include automatic token handling
- Guild-only bots can safely assume
guildIdis always present