Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- client.on('messageReactionAdd', (messageReaction, user) => {
- const { message } = messageReaction
- if (!message.author.bot || user.bot) return;
- // From a JSON file, parsed above:
- //colorRoles: { "🔵": "BLUE", "🟢": "GREEN", "🔴": "RED", "🟡": "YELLOW" }
- const guildRoles = message.guild.roles.cache
- const emojiName = messageReaction.emoji.name
- // If the emoji is 🔵, 🟢, 🔴, or 🟡
- if (colorRoles.hasOwnProperty(emojiName)) {
- // The GuildMember that added the Reaction
- const guildMember = messageReaction.message.guild.members.cache.find(member => member.id === user.id)
- // Find that color's Role name, then add it to the GuildMember
- const addRole = guildRoles.find(role => role.name === colorRoles[emojiName])
- guildMember.roles.add(addRole)
- // Filter colorRoles that aren't the selected one, then remove them from the GuildMember
- const removeRoles = guildRoles.filter(role => Object.values(colorRoles).filter(color => color !== colorRoles[emojiName]).includes(role.name))
- guildMember.roles.remove(removeRoles)
- }
- // Remove other color role reactions by this user (ex. blue is already selected; remove blue when clicking green)
- // Omitted (working)
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement