0
votes

I have this verification system on my server, in which a new member must react to a message to obtain a role that gives permission to see the other channels. So, I wanted to make my bot send a message on a specific channel, greeting them, only when a member gets a specific role (verified)

The problem is: anyone can react in the message to get the verified role over and over again, causing the bot to spam, and I still haven't figured out a way to make this welcome message be sent only once per user

Here is my code:

client.on('guildMemberUpdate', (oldMember, newMember) => {
  const channel = client.channels.cache.get('channelID');

    // If the role(s) are present on the old member object but no longer on the new one (i.e role(s) were removed)
    const removedRoles = oldMember.roles.cache.filter(role => !newMember.roles.cache.has(role.id));
    if (removedRoles.size > 0) console.log(`The roles ${removedRoles.map(r => r.name)} were removed from ${oldMember.displayName}.`);
    // If the role(s) are present on the new member object but are not on the old one (i.e role(s) were added)
    const addedRoles = newMember.roles.cache.filter(role => !oldMember.roles.cache.has(role.id));
    if (addedRoles.size > 0){
    if (newMember.roles.cache.some(role => role.name === 'teste')) {
      let embed = new Discord.MessageEmbed()
        .setTitle("♡﹕welcome!")
        .setDescription("lalalala")
        .setColor("#FFB6C1")
        .setThumbnail("https://cdn.discordapp.com/attachments/806974794461216813/817737054745526304/giffy_2.gif")
      channel.send(`Welcome ${oldMember.user}`, embed)
    }
    console.log(`The roles ${addedRoles.map(r => r.name)} were added to ${oldMember.displayName}.`);
  } 
});

1

1 Answers

0
votes

The code you have added to the guildMemberUpdate event listener is being used to send a welcome message when a verified role is added to a member. It is not running any checks to see if the member has already triggered a welcome message.

It sounds like when a member removes their reaction from the message, it also removes their verified role. You should look at where in your code you are removing roles, and change it so the verified role isn't removed after being added.

If this isn't possible, then consider saving a state in a file or database that can be checked before sending a welcome message.