This guide will go over all of the Discord.js events and how to use them, along with examples. You can use this information in many ways, but the most common would be creating a log system for your Discord bot. I don't suggest just copy pasting, try implementing this with your own code. Happy reading!
If you want to just copy the code you can do so here.
- Channel Events
- Client User Events:
- Debug Events:
- Error Events:
- WebSocket Events:
- Emoji Events:
- Guild Events:
- Guild Member Events:
- Interaction Event:
- Message Events:
- Client Events:
- Role Events:
- User Events:
- Voice Events:
// PARAMETER TYPE DESCRIPTION
// channel Channel The channel that was created
client.on('channelCreate', function (channel) {
console.log(`channelCreate: ${channel}`);
});
// PARAMETER TYPE DESCRIPTION
// channel Channel 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.
// PARAMETER TYPE DESCRIPTION
// channel Channel 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}`);
});
// PARAMETER TYPE DESCRIPTION
// oldChannel Channel The channel before the update
// newChannel Channel The channel after the update
client.on('channelUpdate', function (oldChannel, newChannel) {
console.log(`channelUpdate -> a channel is updated - e.g. name change, topic change`);
});
// PARAMETER TYPE DESCRIPTION
// clientUserGuildSettings ClientUserGuildSettings The new client user guild settings
client.on('clientUserGuildSettingsUpdate', function (clientUserGuildSettings) {
console.log(`clientUserGuildSettingsUpdate -> client user's settings update`);
});
// PARAMETER TYPE DESCRIPTION
// clientUserSettings ClientUserSettings The new client user settings
client.on('clientUserSettingsUpdate', function (clientUserSettings) {
console.log(`clientUserSettingsUpdate -> client user's settings update`);
});
// PARAMETER TYPE DESCRIPTION
// info string The debug information
client.on('debug', function (info) {
console.log(`debug -> ${info}`);
});
// PARAMETER TYPE DESCRIPTION
// error Error The encountered error
client.on('error', function (error) {
console.error(`client's WebSocket encountered a connection error: ${error}`);
});
// PARAMETER TYPE DESCRIPTION
// info string The warning
client.on('warn', function (info) {
console.log(`warn: ${info}`);
});
// PARAMETER TYPE DESCRIPTION
// Event CloseEvent The WebSocket close event
client.on('disconnect', function (event) {
console.log(`The WebSocket has closed and will no longer attempt to reconnect`);
});
client.on('reconnecting', function () {
console.log(`client tries to reconnect to the WebSocket`);
});
// PARAMETER TYPE DESCRIPTION
// replayed number The number of events that were replayed
client.on('resume', function (replayed) {
console.log(`whenever a WebSocket resumes, ${replayed} replays`);
});
// PARAMETER TYPE DESCRIPTION
// emoji Emoji The emoji that was created
client.on('emojiCreate', function (emoji) {
console.log(`a custom emoji is created in a guild`);
});
// PARAMETER TYPE DESCRIPTION
// emoji Emoji The emoji that was deleted
client.on('emojiDelete', function (emoji) {
console.log(`a custom guild emoji is deleted`);
});
// PARAMETER TYPE DESCRIPTION
// oldEmoji Emoji The old emoji
// newEmoji Emoji The new emoji
client.on('emojiUpdate', function (oldEmoji, newEmoji) {
console.log(`a custom guild emoji is updated`);
});
// PARAMETER TYPE DESCRIPTION
// guild Guild The guild that the ban occurred in
// user User The user that was banned
client.on('guildBanAdd', function (guild, user) {
console.log(`a member is banned from a guild`);
});
// PARAMETER TYPE DESCRIPTION
// guild Guild The guild that the unban occurred in
// user User The user that was unbanned
client.on('guildBanRemove', function (guild, user) {
console.log(`a member is unbanned from a guild`);
});
// PARAMETER TYPE DESCRIPTION
// guild Guild The created guild
client.on('guildCreate', function (guild) {
console.log(`the client joins a guild`);
});
// PARAMETER TYPE DESCRIPTION
// guild Guild The guild that was deleted
client.on('guildDelete', function (guild) {
console.log(`the client deleted/left a guild`);
});
// PARAMETER TYPE DESCRIPTION
// guild Guild The guild that has become unavailable
client.on('guildUnavailable', function (guild) {
console.error(`a guild becomes unavailable, likely due to a server outage: ${guild}`);
});
// PARAMETER TYPE DESCRIPTION
// oldGuild Guild The guild before the update
// newGuild Guild The guild after the update
client.on('guildUpdate', function (oldGuild, newGuild) {
console.error(`a guild is updated`);
});
// PARAMETER TYPE DESCRIPTION
// member GuildMember The member that has joined a guild
client.on('guildMemberAdd', function (member) {
console.log(`a user joins a guild: ${member.tag}`);
});
// PARAMETER TYPE DESCRIPTION
// member GuildMember The member that became available
client.on('guildMemberAvailable', function (member) {
console.log(`member becomes available in a large guild: ${member.tag}`);
});
// PARAMETER TYPE DESCRIPTION
// member GuildMember The member that has left/been kicked from the guild
client.on('guildMemberRemove', function (member) {
console.log(`a member leaves a guild, or is kicked: ${member.tag}`);
});
// PARAMETER TYPE DESCRIPTION
// members Array<GuildMember> The members in the chunk
// guild Guild The guild related to the member chunk
client.on('guildMembersChunk', function (members, guild) {
console.error(`a chunk of guild members is received`);
});
// PARAMETER TYPE DESCRIPTION
// oldMember GuildMember The member before the update
// newMember GuildMember The member after the update
client.on('guildMemberUpdate', function (oldMember, newMember) {
console.error(`a guild member changes - i.e. new role, removed role, nickname.`);
});
// PARAMETER TYPE DESCRIPTION
// oldMember GuildMember The member before the presence update
// newMember GuildMember The member after the presence update
client.on('presenceUpdate', function (oldMember, newMember) {
console.log(`a guild member's presence changes`);
});
// PARAMETER TYPE DESCRIPTION
// interaction Interaction The interaction which was created
client.on('interactionCreate', function (interaction) {
console.log(`interaction is created -> ${interaction}`);
});
// PARAMETER TYPE DESCRIPTION
// message Message The created message
client.on('messageCreate', function (message) {
console.log(`message is created -> ${message}`);
});
// PARAMETER TYPE DESCRIPTION
// message Message The deleted message
client.on('messageDelete', function (message) {
console.log(`message is deleted -> ${message}`);
});
// PARAMETER TYPE DESCRIPTION
// messages Collection<Snowflake, Message> The deleted messages, mapped by their ID
client.on('messageDeleteBulk', function (messages) {
console.log(`messages are deleted -> ${messages}`);
});
// PARAMETER TYPE DESCRIPTION
// messageReaction MessageReaction The reaction object
// user User The user that applied the emoji or reaction emoji
client.on('messageReactionAdd', function (messageReaction, user) {
console.log(`a reaction is added to a message`);
});
// PARAMETER TYPE DESCRIPTION
// messageReaction MessageReaction The reaction object
// user User The user that removed the emoji or reaction emoji
client.on('messageReactionRemove', function (messageReaction, user) {
console.log(`a reaction is removed from a message`);
});
// PARAMETER TYPE DESCRIPTION
// message Message The message the reactions were removed from
client.on('messageReactionRemoveAll', function (message) {
console.error(`all reactions are removed from a message`);
});
// 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(`a message is updated`);
});
// 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(`${user.tag} has started typing`);
});
// PARAMETER TYPE DESCRIPTION
// channel Channel The channel the user stopped typing in
// user User The user that stopped typing
client.on('typingStop', function (channel, user) {
console.log(`${user.tag} has stopped typing`);
});
client.on('ready', function () {
console.log(`Logged in as ${client.user.tag}!`);
});
// PARAMETER TYPE DESCRIPTION
// role Role The role that was created
client.on('roleCreate', function (role) {
console.error(`a role is created`);
});
// PARAMETER TYPE DESCRIPTION
// role Role The role that was deleted
client.on('roleDelete', function (role) {
console.error(`a guild role is deleted`);
});
// PARAMETER TYPE DESCRIPTION
// oldRole Role The role before the update
// newRole Role The role after the update
client.on('roleUpdate', function (oldRole, newRole) {
console.error(`a guild role is updated`);
});
// PARAMETER TYPE DESCRIPTION
// user User The user the note belongs to
// oldNote String The note content before the update
// newNote String The note content after the update
client.on('userNoteUpdate', function (user, oldNote, newNote) {
console.log(`a member's note is updated`);
});
// 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(`user's details (e.g. username) are changed`);
});
// PARAMETER TYPE DESCRIPTION
// oldMember GuildMember The member before the voice state update
// newMember GuildMember The member after the voice state update
client.on('voiceStateUpdate', function (oldMember, newMember) {
console.log(`a user changes voice state`);
});
Feel free to reach out to me for support.