An (updated) overview of all events in discord.js V12 with examples in a gist. (Not tested myself)
This is for educational purposes only, not to just straight up copy-paste. Learn from it.
Discord.js Events: Docs (Last edited: Fri, 02 Apr 2021 11:57:57 GMT)
📢 | Last updated: 26 June 2021
const { Client } = require('discord.js');
const client = new Client();
client.login('YourSuperSecretToken');
Emitted whenever a channel is created.
Parameter | Type | Description |
---|---|---|
channel | DMChannel / GuildChannel | The channel that was created. |
client.on("channelCreate", function (channel){
console.log(`channelCreate: ${channel}`);
});
Emitted whenever a channel is deleted.
Parameter | Type | Description |
---|---|---|
channel | DMChannel / GuildChannel | The channel that was deleted. |
client.on("channelDelete", function (channel){
console.log(`channelDelete: ${channel}`);
});
Emitted whenever the pins of a channel are updated.
📢 | Due to the nature of the WebSocket event, not much information can be provided easily here - you need to manually check the pins yourself.
Parameter | Type | Description |
---|---|---|
channel | DMChannel / GuildChannel | The channel that the pins update occurred in. |
time | Date | The time of the pins update. |
client.on("channelPinsUpdate", function (channel, time){
console.log(`channelPinsUpdate: ${channel} | ${time}`);
});
Emitted whenever a channel is updated.
Parameter | Type | Description |
---|---|---|
oldChannel | DMChannel / GuildChannel | The channel before the update. |
newChannel | DMChannel / GuildChannel | The channel after the update. |
client.on("channelUpdate", function (channel){
console.log(`channelUpdate: A channel was updated.`);
});
Emitted for general debugging information.
Parameter | Type | Description |
---|---|---|
info | string | The debug information. |
client.on("debug", function (info){
console.log(`debug: ${info}`);
});
Emitted whenever a custom emoji is created in a guild.
Parameter | Type | Description |
---|---|---|
emoji | GuildEmoji | The emoji that was created. |
client.on("emojiCreate", function (emoji){
console.log(`emojiCreate: ${emoji}`);
});
Emitted whenever a custom emoji is deleted in a guild.
Parameter | Type | Description |
---|---|---|
emoji | GuildEmoji | The emoji that was deleted. |
client.on("emojiDelete", function (emoji){
console.log(`emojiDelete: ${emoji}`);
});
Emitted whenever a custom emoji is created in a guild.
Parameter | Type | Description |
---|---|---|
oldEmoji | GuildEmoji | The old emoji. |
newEmoji | GuildEmoji | The new emoji |
client.on("emojiUpdate", function (oldEmoji, newEmoji){
console.log(`emojiUpdate: An emoji has been updated.`);
});
Emitted when the client encounters an error.
Parameter | Type | Description |
---|---|---|
error | Error | The error encountered. |
client.on("error", function (error){
console.log(`error: ${error}`);
});
Emitted whenever a member is banned from a guild.
Parameter | Type | Description |
---|---|---|
guild | Guild | The guild that the ban occured in. |
user | User | The user that was banned |
client.on("guildBanAdd", function (guild, user){
console.log(`guildBanAdd: A user has been banned from a guild`);
});
Emitted whenever a member is unbanned from a guild.
Parameter | Type | Description |
---|---|---|
guild | Guild | The guild that the unban occured in. |
user | User | The user that was unbanned |
client.on("guildBanRemove", function (guild, user){
console.log(`guildBanRemove: A user has been unbanned from a guild`);
});
Emitted whenever the client joins a guild.
Parameter | Type | Description |
---|---|---|
guild | Guild | The guild that the client joined. |
client.on("guildCreate", function (guild){
console.log(`guildCreate: ${guild}`);
});
Emitted whenever a guild kicks the client or the guild is deleted/left.
Parameter | Type | Description |
---|---|---|
guild | Guild | The guild that the client left/got deleted. |
client.on("guildDelete", function (guild){
console.log(`guildDelete: ${guild}`);
});
Emitted whenever a guild integration is updated.
Parameter | Type | Description |
---|---|---|
guild | Guild | The guild whose integrations were updated. |
client.on("guildIntegrationUpdate", function (guild){
console.log(`guildIntegrationUpdate: ${guild}`);
});
Emitted whenever a user joins a guild.
Parameter | Type | Description |
---|---|---|
member | GuildMember | The member that has joined a guild. |
client.on("guildMemberAdd", function (member){
console.log(`guildMemberAdd: ${member}`);
});
Emitted whenever a member becomes available in a large guild.
Parameter | Type | Description |
---|---|---|
member | GuildMember | The member that became available. |
client.on("guildMemberAvailable", function (member){
console.log(`guildMemberAvailable: ${member}`);
});
Emitted whenever a member leaves a guild, or is kicked.
Parameter | Type | Description |
---|---|---|
member | GuildMember | The member that has left/been kicked from the guild. |
client.on("guildMemberRemove", function (member){
console.log(`guildMemberRemove: ${member}`);
});
Emitted whenever a chunk of guild members (from the same guild) is received.
Parameter | Type | Description |
---|---|---|
member | Collection<Snowflake, Guildmember> | The guild related to the member chunk. |
guild | Guild | The guild related to the member chunk. |
chunk | Object | Properties of the recieved chunk. |
chunk.index | number | Index of the received chunk. |
chunk.count | number | Number of chunks the client should receive. |
chunk.nonce | ?string | Nonce for this chunk. |
client.on("guildMemberChunk", function (member, guild, chunk){
console.log(`guildMemberChunk: I recieved a chunk of guildMembers`);
});
Emitted once a guild member changes speaking state.
Parameter | Type | Description |
---|---|---|
member | GuildMember | The member that started/stopped speaking. |
speaking | ReadOnly | The speaking state of the member |
client.on("guildMemberSpeaking", function (member, speaking){
console.log(`guildMemberSpeaking: A member started/stopped speaking`);
});
Emitted whenever a guild member changes.
Parameter | Type | Description |
---|---|---|
oldMember | GuildMember | The member before the update. |
newMember | GuildMember | The member after the update. |
client.on("guildMemberUpdate", function (guild, user){
console.log(`guildMemberUpdate: A member has been changed`);
});
Emitted whenever a guild becomes unavailable, likely due to a server outage.
Parameter | Type | Description |
---|---|---|
guild | Guild | The guild that the ban occured in. |
client.on("guildUnavailable", function (guild, user){
console.log(`guildUnavailable: ${guild}`);
});
Emitted whenever a member is banned from a guild.
Parameter | Type | Description |
---|---|---|
oldGuild | Guild | The guild before the update. |
newGuild | Guild | The guild after the update. |
client.on("guildUpdate", function (guild, user){
console.log(`guildUpdate: A guild has been updated`);
});
Emitted whenever the client's session becomes invalidated.
📢 | You are expected to handle closing the process gracefully and preventing a boot loop if you are listening to this event.
client.on("invalidated", function (){
console.log(`invalidated: My session became invalidated`);
});
Emitted when an invite is created.
📢 | This event only triggers if the client has
MANAGE_GUILD
permissions for the guild, orMANAGE_CHANNEL
permissions for the channel.
Parameter | Type | Description |
---|---|---|
invite | Invite | The invite that has been created. |
client.on("inviteCreate", function (invite){
console.log(`inviteCreate: ${invite}`);
});
Emitted when an invite is deleted.
📢 | This event only triggers if the client has
MANAGE_GUILD
permissions for the guild, orMANAGE_CHANNEL
permissions for the channel.
Parameter | Type | Description |
---|---|---|
invite | Invite | The invite that has been created. |
client.on("inviteDelete", function (invite){
console.log(`inviteDelete: ${invite}`);
});
Emitted whenever a message is created.
Parameter | Type | Description |
---|---|---|
message | Message | The created message. |
client.on("message", function (message){
console.log(`message: ${message}`);
});
Emitted whenever a message is deleted.
Parameter | Type | Description |
---|---|---|
message | Message | The deleted message. |
client.on("messageDelete", function (message){
console.log(`messageDelete: ${message}`);
});
Emitted whenever messages are deleted in bulk.
Parameter | Type | Description |
---|---|---|
messages | Collection<Snowflake, Message> | The deleted messages, mapped by their ID. |
client.on("messageDeleteBulk", function (messages){
console.log(`messageDeleteBulk: ${message.size} messages were bulkdeleted`);
});
Emitted whenever a reaction is added to a cached message.
Parameter | Type | Description |
---|---|---|
messageReaction | MessageReaction | The reaction object. |
user | User | The user that applied the guild or reaction emoji. |
client.on("messageReactionAdd", function (messageReaction, user){
console.log(`messageReactionAdd: A user applied the guild or reaction emoji`);
});
Emitted whenever a reaction is removed from a cached message.
Parameter | Type | Description |
---|---|---|
messageReaction | MessageReaction | The reaction object. |
user | User | The user whose emoji or reaction was removed. |
client.on("messageReactionRemove", function (messageReaction, user){
console.log(`messageReactionRemove: An emoji or reaction emoji was removed`);
});
Emitted whenever all reactions are moved from a cached message..
Parameter | Type | Description |
---|---|---|
message | Message | The message the reactions were removed from. |
client.on("messageReactionRemoveAll", function (message){
console.log(`messageReactionRemoveAll: All reactions were removed from a message`);
});
Emitted whenever a bot removes an emoji reaction from a cached message.
Parameter | Type | Description |
---|---|---|
reaction | MessageReaction | The reaction that was removed. |
client.on("messageReactionRemoveEmoji", function (reaction){
console.log(`messageReactionRemoveEmoji: A bot removed a raction from a message`);
});
Emitted whenever a message is updated.
Parameter | Type | Description |
---|---|---|
oldMessage | Message | The message before the update. |
newMessage | Message | The message after the update. |
client.on("messageUpdate", function (oldMessage, newMessage){
console.log(`messageUpdate: A message was updated`);
});
Emitted whenever guild member's presence is changed.
Parameter | Type | Description |
---|---|---|
oldPresence | ?Presence | The presence before the update, if one at all. |
newPresence | Presence | The presence after the update. |
client.on("presenceUpdate", function (oldPresence, newPresence){
console.log(`presenceUpdate: A user reacted on a message`);
});
Emitted whenever the client hits a rate limit while making a request.
Parameter | Type | Description |
---|---|---|
rateLimitInfo | Object | Object containing the rate limit info. |
rateLimitInfo.timeout | number | Timeout in ms. |
rateLimitInfo.limit | number | Number of requests that can be made to this endpoint. |
rateLimitInfo.method | string | HTTP method used for request that triggerd this event. |
rateLimitInfo.path | string | Path used for request that triggerd this event. |
rateLimitInfo.route | string | Route used for request that triggerd this event. |
client.on("rateLimit", function (rateLimitInfo){
console.log(`rateLimit: ${rateLimitInfo}`);
});
Emitted whenever the client becomes ready to start working.
client.on("ready", function () {
console.log(`ready: Logged in as ${client.user.tag}`);
});
Emitted whenever a role is created.
Parameter | Type | Description |
---|---|---|
role | Role | The role that was created. |
client.on("roleCreate", function (role){
console.log(`roleCreate: ${role}`);
});
Emitted whenever a role is deleted.
Parameter | Type | Description |
---|---|---|
role | Role | The role that was deleted. |
client.on("roleDelete", function (role){
console.log(`roleDelete: ${role}`);
});
Emitted whenever a role is created.
Parameter | Type | Description |
---|---|---|
oldRole | Role | The role before the update. |
newRole | Role | The role after the update. |
client.on("roleUpdate", function (oldRole, newRole){
console.log(`roleUpdate: A role has changed`);
});
Emitted whenever a shard's WebSocket disconnects and will no longer reconnect.
Parameter | Type | Description |
---|---|---|
event | CloseEvent | The Websocket close event. |
id | number | The shard ID that disconnected. |
client.on("shardDisconnect", function (event, id){
console.log(`shardDisconnect: Shard #${id} disconnected`);
});
Emitted whenever a shard's WebSocket encounters a connection error.
Parameter | Type | Description |
---|---|---|
error | Error | The encountered error. |
id | number | The shard ID that encountered this error. |
client.on("shardError", function (error, id){
console.log(`shardError: Shard #${id} encountered a error`);
});
Emitted when a shard turns ready
Parameter | Type | Description |
---|---|---|
id | number | The shard ID that disconnected. |
unavailableGuilds | ?Set | Set of unavailable guild ID's, if any. |
client.on("shardReady", function (event, id){
console.log(`shardReady: Shard #${id} is ready`);
});
Emitted when a shard is attempting to reconnect or re-identify.
Parameter | Type | Description |
---|---|---|
id | number | The shard ID that is attempting to reconnect. |
client.on("shardReconnecting", function (id){
console.log(`shardReconnecting: Shard #${id} is trying to reconnect...`);
});
Emitted when a shard resumes succesfully.
Parameter | Type | Description |
---|---|---|
id | number | The shard ID that resumed. |
replayedEvents | number | The amount of replayed events. |
client.on("shardResume", function (id, replayedEvents){
console.log(`shardResume: Shard #${id} resumes`);
});
Emitted whenever a user starts typing in a channel.
Parameter | Type | Description |
---|---|---|
channel | Channel | The channel the user started typing in. |
user | User | The user that started typing. |
client.on("typingStart", function (channel, user){
console.log(`typingStart: ${user} started typing in ${channel}`);
});
Emitted when a user's details are changed.
📢 | Triggered by the Discord gateway events
USER_UPDATE
,GUILD_MEMBER_UPDATE
, andPRESENCE_UPDATE
.
Parameter | Type | Description |
---|---|---|
oldUser | User | The user before the update. |
newUser | User | The user after the update. |
client.on("userUpdate", function (oldUser, newUser){
console.log(`userUpdate: User has changed their details`);
});
Emitted when a member changes voice state.
Parameter | Type | Description |
---|---|---|
oldState | VoiceState | The voice state before the update. |
newState | VoiceState | The voice state after the update. |
client.on("voiceState", function (id){
console.log(`voiceState: A member changed their voice state`);
});
Emitted for general warnings.
Parameter | Type | Description |
---|---|---|
info | string | The warning. |
client.on("warn", function (info){
console.log(`warn: ${info}`);
});
Emitted whenever a guild texxt channel has its webhooks changed.
Parameter | Type | Description |
---|---|---|
channel | TextChannel | The channel that had a webhook update. |
client.on("webhookUpdate", function (channel){
console.log(`webhookUpdate: ${channel}`);
});