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}.`);
}
});