Overview
Theon() function registers event handlers for Discord gateway events. Use it to respond to messages, reactions, interactions, and other bot events.
Signature
Parameters
The name of the event to listen for. See Available Events below.
Async or sync function that receives the event context
Available Events
ready
Fired when the bot successfully connects to Discord.msg.user- The bot user objectmsg.guildIds- Array of guild IDs the bot is in
messageCreate
Fired when a new message is sent in a channel the bot can see.msg.id- Message IDmsg.content- Message textmsg.author- User who sent the messagemsg.channelId- Channel IDmsg.guildId- Guild ID (if in a server)msg.member- Member object (if in a server)reply()- Reply to the messageedit()- Edit the message (bot messages only)
messageUpdate
Fired when a message is edited.msg.id- Message IDmsg.content- New content (partial)msg.old- Previous message state (if cached)msg.new- New message state (if cached)msg.editedTimestamp- ISO8601 timestamp of edit
messageDelete
Fired when a message is deleted.msg.id- Deleted message IDmsg.channelId- Channel IDmsg.guildId- Guild ID
messageDeleteBulk
Fired when multiple messages are deleted at once.msg.ids- Array of deleted message IDsmsg.channelId- Channel IDmsg.guildId- Guild ID
interactionCreate
Fired when a slash command is invoked. Usually handled automatically bycreateBot().
msg.commandName- Name of the commandmsg.interactionId- Unique interaction IDmsg.interactionToken- Token for respondingmsg.user- User who invoked the commandmsg.member- Member object (if in guild)msg.data- Raw interaction dataoptions- Flattened command optionsreply()- Respond to the interaction
componentInteraction
Fired when a user interacts with a button or select menu.msg.interactionId- Unique interaction IDmsg.interactionToken- Token for respondingmsg.user- User who clickedmsg.data- Component interaction data (includescustom_id)msg.messageId- ID of message containing the componentreply()- Respond to the interaction
modalSubmit
Fired when a user submits a modal (form).msg.interactionId- Unique interaction IDmsg.interactionToken- Token for respondingmsg.user- User who submittedmsg.data- Modal submission datareply()- Respond to the submission
reactionAdd
Fired when a reaction is added to a message.msg.userId- User who reactedmsg.messageId- Message that was reacted tomsg.channelId- Channel IDmsg.emoji- Emoji objectmsg.burst- Whether itβs a super reaction
reactionRemove
Fired when a reaction is removed from a message.reactionAdd
reactionRemoveEmoji
Fired when all instances of a specific emoji are removed.reactionAdd
reactionRemoveAll
Fired when all reactions are removed from a message.msg.messageId- Message IDmsg.channelId- Channel IDmsg.guildId- Guild ID
Multiple Handlers
You can register multiple handlers for the same event:Notes
- Event handlers can be async or sync
- Multiple handlers for the same event are supported
- The
readyevent fires once when the bot connects - Most events include
reply()andedit()helper methods - For slash commands, use
createBot()instead of manually handlinginteractionCreate