Skip to main content

๐Ÿ’ฌ Message

๐ŸŽŠ Multi eventsโ€‹

There is 3 kinds of events here:

Since we have 3 kinds of events, we can no longer simply put them in ./sources/modules/<module_name>/messages, we need to specify which of the 3 events is to be used. To do this, we add an extension to the end of the file:

โŽฏ Example for each classes replace <module_name> by the name of your module

  • create โ†’ ./sources/modules/<module_name>/messages/create.js
  • delete โ†’ ./sources/modules/<module_name>/messages/delete.js
  • update โ†’ ./sources/modules/<module_name>/messages/update.js

๐Ÿค” "Message"โ€‹

Message is an object with several data and methods, you should read discord.js documentation to see how to work with Message.

โž• MessageCreateโ€‹

Has one argument message who is an instance of Message.

async function parse(message)
{
console.log("new message from:", message.author.username)
console.log("content:", message.content)
}

module.exports = {
parse,
conditions: [],
any_guild: false,
dm: false,
allow_bots: false
}

โž– MessageDeleteโ€‹

Has one argument message who is an instance of Message.

async function parse(message)
{
console.log("message from:", message.author.username, "has been deleted")
console.log("content:", message.content)
}

module.exports = {
parse,
conditions: [],
any_guild: false,
dm: false,
allow_bots: false
}

๐Ÿ†™ MessageUpdateโ€‹

Has two arguments old_message and new_message who are instances of Message.

โš ๏ธ Warning: old_message is the message state before the update and new_message after the update.

async function parse(old_message, new_message)
{
console.log("message from:", old_message.author.username, "has been updated")
console.log("old_content:", old_message.content)
console.log("new_message:", new_message.content)
}

module.exports = {
parse,
conditions: [],
any_guild: false,
dm: false,
allow_bots: false
}

๐Ÿ–ฅ๏ธ Methods and parametersโ€‹

Be careful MessageCreate and MessageDelete both has only one argument so as shown below:

async function parse(message)

While MessageUpdate has 2 arguments

async function parse(old_message, new_message)

โŽฏ Exports

At the bottom of the file we have exports, which includes several important elements.

module.exports = {
parse,
conditions: [],
any_guild: false,
dm: false,
allow_bots: false
}
  • parse โ†’ method to handle the event
  • conditions โ†’ list of methods to check if message.member has the right conditions
  • any_guild โ†’ if false, the command can be executed only on the main guild
  • dm โ†’ if true, we can use this interaction in direct messages
  • allow_bots โ†’ if false, it will ignore events when the member is a bot