Skip to main content

๐Ÿง‘โ€๐Ÿง‘โ€๐Ÿง’โ€๐Ÿง’ Members

โ„น๏ธ Magic tipsโ€‹

If you want to create "fake join" or "fake leave" to test you handlers, you can use builtin commands : join and leave.

๐ŸŽŠ Multi eventsโ€‹

There is 3 kinds of events here:

  • MemberAdd โ†’ (we will call it MemberJoin, it's easier to understand) when a user join a guild
  • MemberRemove โ†’ (we will call it MemberLeave, it's easier to understand) when a user leave a guild
  • MemberUpdate โ†’ when a member (user inside a guild) is updated (e.g: new role)

Since we have 3 kinds of events, we can no longer simply put them in ./sources/modules/<module_name>/members, 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

  • join โ†’ ./sources/modules/<module_name>/members/member_join.js
  • leave โ†’ ./sources/modules/<module_name>/members/member_leave.js
  • update โ†’ ./sources/modules/<module_name>/members/member_update.js

๐Ÿค” "Member"โ€‹

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

โž• MemberJoinโ€‹

Has one argument member who is an instance of Member.

async function parse(member)
{
console.log("new member:", member.user.username)
}

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

โž– MemberLeaveโ€‹

Possรจde un argument member qui est une instance de Member.

async function parse(member)
{
console.log("a member left:", member.user.username)
}

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

๐Ÿ†™ MemberUpdateโ€‹

Possรจde deux arguments old_member et new_member qui sont des instances de Member.

โš ๏ธ Attention: old_member est l'รฉtat du membre avant la mise ร  jour et new_member aprรจs la mise ร  jour.

async function parse(old_member, new_member)
{
console.log("member: ", old_member.user.username, " has been updated")
}

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

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

Be careful MemberJoin and MemberLeave both has only one argument so as shown below:

async function parse(member)

While MemberUpdate has 2 arguments

async function parse(old_member, new_member)

โŽฏ 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 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