Advertisement
mqunell

Untitled

Sep 16th, 2020 (edited)
645
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. client.on('messageReactionAdd', (messageReaction, user) => {
  2.     const { message } = messageReaction
  3.  
  4.     if (!message.author.bot || user.bot) return;
  5.  
  6.     // From a JSON file, parsed above:
  7.     //colorRoles: { "🔵": "BLUE", "🟢": "GREEN", "🔴": "RED", "🟡": "YELLOW" }
  8.     const guildRoles = message.guild.roles.cache
  9.     const emojiName = messageReaction.emoji.name
  10.  
  11.     // If the emoji is 🔵, 🟢, 🔴, or 🟡
  12.     if (colorRoles.hasOwnProperty(emojiName)) {
  13.         // The GuildMember that added the Reaction
  14.         const guildMember = messageReaction.message.guild.members.cache.find(member => member.id === user.id)
  15.  
  16.         // Find that color's Role name, then add it to the GuildMember
  17.         const addRole = guildRoles.find(role => role.name === colorRoles[emojiName])
  18.         guildMember.roles.add(addRole)
  19.  
  20.         // Filter colorRoles that aren't the selected one, then remove them from the GuildMember
  21.         const removeRoles = guildRoles.filter(role => Object.values(colorRoles).filter(color => color !== colorRoles[emojiName]).includes(role.name))
  22.         guildMember.roles.remove(removeRoles)
  23.     }
  24.  
  25.     // Remove other color role reactions by this user (ex. blue is already selected; remove blue when clicking green)
  26.     // Omitted (working)
  27. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement