๐ฌ Message
๐ Multi eventsโ
There is 3 kinds of events here:
MessageCreateโ when a message is sentMessageDeleteโ when a message is deletedMessageUpdateโ when a message is updated
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:
createโ to handleMessageCreatedeleteโ to handleMessageDeleteupdateโ to handleMessageUpdate
โฏ Example for each classes
replace <module_name> by the name of your module
createโ./sources/modules/<module_name>/messages/create.jsdeleteโ./sources/modules/<module_name>/messages/delete.jsupdateโ./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 eventconditionsโ list of methods to check ifmessage.memberhas the right conditionsany_guildโ if false, the command can be executed only on the main guilddmโ if true, we can use this interaction in direct messagesallow_botsโ if false, it will ignore events when the member is a bot