iiTzMrPierce

Rle-React-Message

Oct 18th, 2020
694
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const firstMessage = require('./first-message')
  2.  
  3. module.exports = (client) => {
  4.   const channelId = '767249126747275334'
  5.  
  6.   const getEmoji = (emojiName) =>
  7.     client.emojis.cache.find((emoji) => emoji.name === emojiName)
  8.  
  9.   const emojis = {
  10.     Sunspire: 'vSS',
  11.     KynesAegis: 'vKA',
  12.   }
  13.  
  14.   const reactions = []
  15.  
  16.   let emojiText = 'Add a reaction to claim a role\n\n'
  17.   for (const key in emojis) {
  18.     const emoji = getEmoji(key)
  19.     reactions.push(emoji)
  20.  
  21.     const role = emojis[key]
  22.     emojiText += `${emoji} = ${role}\n`
  23.   }
  24.  
  25.   firstMessage(client, channelId, emojiText, reactions)
  26.  
  27.   const handleReaction = (reaction, user, add) => {
  28.     if (user.id === '764865488048095233') {
  29.       return
  30.     }
  31.  
  32.     const emoji = reaction._emoji.name
  33.  
  34.     const { guild } = reaction.message
  35.  
  36.     const roleName = emojis[emoji]
  37.     if (!roleName) {
  38.       return
  39.     }
  40.  
  41.     const role = guild.roles.cache.find((role) => role.name === roleName)
  42.     const member = guild.members.cache.find((member) => member.id === user.id)
  43.  
  44.     if (add) {
  45.       member.roles.add(role)
  46.     } else {
  47.       member.roles.remove(role)
  48.     }
  49.   }
  50.  
  51.   client.on('messageReactionAdd', (reaction, user) => {
  52.     if (reaction.message.channel.id === channelId) {
  53.       handleReaction(reaction, user, true)
  54.       console.log('Test')
  55.     }
  56.   })
  57.  
  58.   client.on('messageReactionRemove', (reaction, user) => {
  59.     if (reaction.message.channel.id === channelId) {
  60.       handleReaction(reaction, user, false)
  61.     }
  62.   })
  63. }
RAW Paste Data