๐ช Channels
๐ Multi eventsโ
There is 3 kinds of events here:
ChannelCreateโ when a channel is createdChannelDeleteโ when a channel is deletedChannelUpdateโ when a channel is updated
Since we have 3 kinds of events, we can no longer simply put them in ./sources/modules/<module_name>/channels,
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 handleChannelCreatedeleteโ to handleChannelDeleteupdateโ to handleChannelUpdate
โฏ Example for each classes
replace <module_name> by the name of your module
createโ./sources/modules/<module_name>/channels/create.jsdeleteโ./sources/modules/<module_name>/channels/delete.jsupdateโ./sources/modules/<module_name>/channels/update.js
๐ค "Channel"โ
Channel is an object with several data and methods, you should read
discord.js documentation to see
how to work with Channel.
โ ChannelCreateโ
Has one argument channel who is an instance of Channel.
async function parse(channel)
{
console.log("new message from:", message.author.username)
console.log("content:", message.content)
}
module.exports = {
parse,
conditions: [],
any_guild: false,
dm: false,
}
โ ChannelDeleteโ
Has one argument channel who is an instance of Channel.
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,
}
๐ ChannelUpdateโ
Has two arguments old_channel and new_channel who are instances of Channel.
โ ๏ธ Warning: old_channel is the channel state before the update and new_channel after the update.
async function parse(old_channel, new_channel)
{
console.log("channel:", old_channel.name, "has been updated")
console.log("old_channel:", old_channel)
console.log("new_channel:", new_channel)
}
module.exports = {
parse,
conditions: [],
any_guild: false,
dm: false,
allow_bots: false
}
๐ฅ๏ธ Methods and parametersโ
Be careful ChannelCreate and ChannelDelete both has only one argument so as shown below:
async function parse(message)
While ChannelUpdate has 2 arguments
async function parse(old_channel, new_channel)
โฏ Exports
At the bottom of the file we have exports, which includes several important elements.
module.exports = {
parse,
conditions: [],
any_guild: false,
dm: false,
}
parseโ method to handle the eventconditionsโ list of methods to check ifchannelhas 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 messages