Skip to main content

๐Ÿช‘ Channels

๐ŸŽŠ 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>/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:

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

  • create โ†’ ./sources/modules/<module_name>/channels/create.js
  • delete โ†’ ./sources/modules/<module_name>/channels/delete.js
  • update โ†’ ./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 event
  • conditions โ†’ list of methods to check if channel 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