i'm working on a function reaction role bot. I'm trying to find out how I would add a filter that would ignore other emojis outside the ones I have assigned. The bot works fine except when I or others try to react with the bot with emojis outside of the ones I have assigned.
client.on('message', message => {
if(message.author.bot || message.embeds)
embedMsg = message.embeds.find(msg => msg.title === 'Server Roles') ? message : undefined
if(embedMsg)
{
embedMsg.react('755602275963109536')
.then
(reaction => reaction.message.react('755604749814071366'))
.then(reaction => reaction.message.react('755605241067601960'))
.then(reaction => reaction.message.react('755604978571280466'))
.then(reaction => reaction.message.react('755604795292909589'))
.then(reaction => reaction.message.react('755605048666620075'))
.then(reaction => reaction.message.react('755604953229164594'))
.then(reaction => reaction.message.react('755604994656436346'))
.then(reaction => reaction.message.react('755605995195072603'))
.then(reaction => reaction.message.react('755605032124022814'))
.then(reaction => reaction.message.delete(20000))
.then(msg => console.log("Deleted message"))
.catch(() => console.error('One of the emojis failed to react.'));
return;
}
client.on('messageReactionAdd', (reaction, user) => {
if (user.bot) return;
var roleName = reaction.emoji.name;
console.log(roleName);
var role = reaction.message.guild.roles.find(
role => role.name.toLowerCase() === roleName.toLowerCase()
);
var member = reaction.message.guild.members.find(
(member) => member.id === user.id
);
//remove role
if (member.roles.has(role.id)) {
member
.removeRole(role.id)
.then((member) => {
console.log(
'Removed' + member.user.username + ' from the ' + role.name + ' role.'
);
})
.catch((err) => console.error);
//add role
} else {
member
.addRole(role.id)
.then((member) => {
console.log(
'Added ' + member.user.username + ' to the ' + role.name + ' role.'
);
})
.catch((err) => console.error);
}
});
You can make an array of accepted emoji IDs, and test each one against the reaction given.
const array = ['ID #1, 'ID #2', 'ID #3', 'etc.'];
if (!array.includes(reaction.emoji.id)) return;