Discord Events
Table of Contents
aoi.js offers various event listeners, also known as “events,” which cover most of the events provided by the Discord API.
Each event serves a specific purpose and requires a particular command type to execute designated tasks, such as logging activities.
The events are not mandatory, except for onMessage
, which is essential for the bot to read and send messages. If you wish to use other events, you must include them in your main file so your bot can listen to these events. This step is necessary to utilize various command types.
It’s important to note that activating your intents on the Discord Developer Portal is required to utilize certain events.
Types of Events
Message Based-Events
- onMessage → Emitted whenever a message is sent. (requires message content intent)
- onMessageDelete → Emitted whenever a message is deleted.
messageDelete
→ Command Handler type.
- onMessageUpdate → Emitted whenever a message is updated (for example, embed or content change).
messageUpdate
→ Command Handler type.$oldMessage
→ Retrieves the old message from the client’s cache. (if any)$message
→ Retrieves the new message. (if any)
- onMessageDeleteBulk → Emitted whenever messages are deleted in bulk.
messageDeleteBulk
→ Command Handler type.
- onReactionAdd → Emitted whenever a reaction is added to a message.
reactionAdd
→ Command Handler type.
- onReactionRemove → Emitted whenever a reaction is removed from a message.
reactionRemove
→ Command Handler type.
- onReactionRemoveAll → Emitted whenever all reactions are removed from a message.
reactionRemoveAll
→ Command Handler type.
Guild Based-Events
- onInviteCreate → Emitted whenever a guild invite is created.
inviteCreate
→ Command Handler type.
- onInviteDelete → Emitted whenever a guild invite is deleted.
inviteDelete
→ Command Handler type.
- onGuildJoin → Emitted whenever the client joins a guild.
guildJoin
→ Command Handler type.
- onGuildLeave → Emitted whenever the client leaves a guild.
guildLeave
→ Command Handler type.
- onGuildUpdate → Emitted whenever a guild gets updated (for example, name change).
guildUpdate
→ Command Handler type.
$oldGuild[option?]
→ Retrieves data of the old guild. (if any)$newGuild[option?]
→ Retrieves data of the new/updated guild. (if any)
- onGuildUnavailable → Emitted whenever a guild becomes unavailable, likely due to a server outage.
guildUnavailable
→ Command Handler type.
- onRoleCreate → Emitted whenever a role is created.
roleCreate
→ Command Handler type.
- onRoleUpdate → Emitted whenever a role gets updated (for example, color change).
roleUpdate
→ Command Handler type.
$oldRole[option?]
→ Retrieves data of the old role. (if any)$newRole[option?]
→ Retrieves data of the new/updated role. (if any)
- onRoleDelete → Emitted whenever a role is deleted.
roleDelete
→ Command Handler type.
- onChannelCreate → Emitted whenever a channel is created.
channelCreate
→ Command Handler type.
- onChannelUpdate → Emitted whenever a channel gets updated. (for example, topic change).
channelUpdate
→ Command Handler type.
$oldChannel[option?]
→ Retrieves data of the old channel. (if any)$newChannel[option?]
→ Retrieves data of the new/updated channel. (if any)
- onChannelDelete → Emitted whenever a channel is deleted.
channelDelete
→ Command Handler type.
- onChannelPinsUpdate → Emitted whenever the pins of a channel are updated.
channelPinsUpdate
→ Command Handler type.
- onStageInstanceCreate → Emitted whenever a stage instance is created.
stageInstanceCreate
→ Command Handler type.
- onStageInstanceUpdate → Emitted whenever a stage instance gets updated.
stageInstanceUpdate
→ Command Handler type.
- onStageInstanceDelete → Emitted whenever a stage instance is deleted.
stageInstanceDelete
→ Command Handler type.
- onThreadCreate → Emitted whenever a thread is created.
threadCreate
→ Command Handler type.
- onThreadUpdate → Emitted whenever a thread gets updated.
threadUpdate
→ Command Handler type.
- onThreadDelete → Emitted whenever a thread is deleted.
threadDelete
→ Command Handler type.
- onThreadListSync → Emitted whenever the client user gains access to a text or news channel that contains threads.
threadListSync
→ Command Handler type.
- onThreadMemberUpdate → Emitted whenever the client user’s thread member is updated. (requires guild members intent)
threadMemberUpdate
→ Command Handler type.
- onThreadMembersUpdate → Emitted whenever members are added or removed from a thread. (requires guild members intent)
threadMembersUpdate
→ Command Handler type.
- onEmojiCreate → Emitted whenever a custom emoji is created in a guild.
emojiCreate
→ Command Handler type.
- onEmojiDelete → Emitted whenever a custom emoji is deleted in a guild.
emojiDelete
→ Command Handler type.
- onEmojiUpdate → Emitted whenever a custom guild emoji is updated.
emojiUpdate
→ Command Handler type.
$oldEmoji[option?]
→ Retrieves data of the old emoji. (if any)$newEmoji[option?]
→ Retrieves data of the new emoji. (if any)
- onStickerCreate → Emitted whenever a custom sticker is created in a guild.
stickerCreate
→ Command Handler type.
- onStickerDelete → Emitted whenever a custom sticker gets deleted in a guild.
stickerDelete
→ Command Handler type.
- onStickerUpdate → Emitted whenever a custom sticker is updated in a guild.
stickerUpdate
→ Command Handler type.
$oldEmoji[option?]
→ Retrieves data of the old sticker. (if any)$newEmoji[option?]
→ Retrieves data of the new sticker. (if any)
- onBanAdd → Emitted whenever a member is banned from a guild.
banAdd
→ Command Handler type.
- onBanRemove → Emitted whenever a member is unbanned from a guild.
banRemove
→ Command Handler type.
- onVoiceStateUpdate → Emitted whenever a user changes voice state (for example, joins/leaves a channel, mutes/unmutes).
voiceStateUpdate
→ Command Handler type.
$oldState[option?]
→ Retrieves data of the old voice state. (if any)$newState[option?]
→ Retrieves data of the new voice state. (if any)
- onWebhooksUpdate → Emitted whenever a channel has its webhooks changed.
webhooksUpdate
→ Command Handler type.
Guild Members Based-Events
- onJoin → Emitted whenever a user joins a guild.
join
→ Command Handler type.
- onLeave → Emitted whenever a member leaves a guild, or is kicked.
leave
→ Command Handler type.
- onMemberUpdate → Emitted whenever a guild member changes (for example, new role, removed role, nickname). (requires guild members intent)
memberUpdate
→ Command Handler type.
$oldMember[option?]
→ Retrieves data of the old member. (if any)$newMember[option?]
→ Retrieves data of the new/updated member. (if any)
- onMemberAvailable → Emitted whenever a member becomes available in a large guild. (requires guild members intent)
memberAvailable
→ Command Handler type.
- onMembersChunk → Emitted whenever a chunk of guild members is received (all members come from the same guild). (requires guild members intent)
membersChunk
→ Command Handler type.
User Based-Events
- onPresenceUpdate → Emitted whenever a guild member’s presence changes, or they change one of their details.
presenceUpdate
→ Command Handler type.
$oldPresence[option]
→ Retrieves data of the old presence. (if any)$newPresence[option]
→ Retrieves data of the new presence. (if any)
- onTypingStart → Emitted whenever a user starts typing in a channel.
typingStart
→ Command Handler type.
- onUserUpdate → Emitted whenever a user’s details (for example, username) are changed.
userUpdate
→ Command Handler type.
$oldUser[option]
→ Retrieves data of the old user. (if any)$newUser[option]
→ Retrieves data of the updated/new user. (if any)
Custom Events
- onInteractionCreate → Emitted whenever an Interaction is created.
- onFunctionError → Emitted whenever a command or function returns an error message.
- onApplicationCommandPermissionsUpdate → Emitted whenever an Application Command gets updated (for example, name).
$oldApplicationCmd[option?]
→ Retrieves data of the old application command.$newApplicationCmd[option?]
→ Retrieves data of the updated application command.
- onVariableCreate → Emitted whenever a variable is created.
- onVariableDelete → Emitted whenever a variable gets deleted.
- onVariableUpdate → Emitted whenever a variable gets updated.
$oldVariable[opt;separator?]
→ Retrieves the old data of the variable. (if any)$newVariable[opt;separator?]
→ Retrieves the new/updated data of the variable. (if any)
- onShardDisconnect → Emitted whenever the client’s shard disconnects.
- onShardError → Emitted whenever a shard of the client returns an error.
- onShardReady → Emitted whenever a shard of the client is ready.
- onShardReconnecting → Emitted whenever a shard of the client is currently reconnecting.
- onShardResume → Emitted whenever the shard resumed operations.