Advertisement
Guest User

Untitled

a guest
Dec 8th, 2020
30,171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const Discord = require('discord.js');
  2.  
  3. const client = new Discord.Client({ partials: ["MESSAGE", "CHANNEL", "REACTION" ]});
  4.  
  5. const prefix = '-';
  6.  
  7. const fs = require('fs');
  8.  
  9. client.commands = new Discord.Collection();
  10.  
  11. const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
  12. for (const file of commandFiles) {
  13.     const command = require(`./commands/${file}`);
  14.  
  15.     client.commands.set(command.name, command);
  16. }
  17.  
  18.  
  19. client.on('ready', () => {
  20.     console.log('bot is online!');
  21. });
  22.  
  23.  
  24. client.on('message', message => {
  25.  
  26.     if (!message.content.startsWith(prefix) || message.author.bot) return;
  27.  
  28.     const args = message.content.slice(prefix.length).split(/ +/);
  29.     const command = args.shift().toLowerCase();
  30.     if (command === 'reactionrole') {
  31.         client.commands.get('reactionrole').execute(message, args, Discord, client);
  32.     }
  33.  
  34. });
  35.  
  36. client.login('YOUR_TOKEN');
  37.  
  38.  
  39. -------------------------------- ReactionRole.js --------------------------------
  40.  
  41. module.exports = {
  42.     name: 'reactionrole',
  43.     description: "Sets up a reaction role message!",
  44.     async execute(message, args, Discord, client) {
  45.         const channel = 'YOUR_CHANNEL';
  46.         const yellowTeamRole = message.guild.roles.cache.find(role => role.name === "YOUR_ROLE");
  47.         const blueTeamRole = message.guild.roles.cache.find(role => role.name === "YOUR_ROLE");
  48.  
  49.         const yellowTeamEmoji = 'YOUR_EMOJI';
  50.         const blueTeamEmoji = 'YOUR_EMOJI';
  51.  
  52.         let embed = new Discord.MessageEmbed()
  53.             .setColor('#e42643')
  54.             .setTitle('Choose a team to play on!')
  55.             .setDescription('Choosing a team will allow you to interact with your teammates!\n\n'
  56.                 + `${yellowTeamEmoji} for yellow team\n`
  57.                 + `${blueTeamEmoji} for blue team`);
  58.  
  59.         let messageEmbed = await message.channel.send(embed);
  60.         messageEmbed.react(yellowTeamEmoji);
  61.         messageEmbed.react(blueTeamEmoji);
  62.  
  63.         client.on('messageReactionAdd', async (reaction, user) => {
  64.             if (reaction.message.partial) await reaction.message.fetch();
  65.             if (reaction.partial) await reaction.fetch();
  66.             if (user.bot) return;
  67.             if (!reaction.message.guild) return;
  68.  
  69.             if (reaction.message.channel.id == channel) {
  70.                 if (reaction.emoji.name === yellowTeamEmoji) {
  71.                     await reaction.message.guild.members.cache.get(user.id).roles.add(yellowTeamRole);
  72.                 }
  73.                 if (reaction.emoji.name === blueTeamEmoji) {
  74.                     await reaction.message.guild.members.cache.get(user.id).roles.add(blueTeamRole);
  75.                 }
  76.             } else {
  77.                 return;
  78.             }
  79.  
  80.         });
  81.  
  82.         client.on('messageReactionRemove', async (reaction, user) => {
  83.  
  84.             if (reaction.message.partial) await reaction.message.fetch();
  85.             if (reaction.partial) await reaction.fetch();
  86.             if (user.bot) return;
  87.             if (!reaction.message.guild) return;
  88.  
  89.  
  90.             if (reaction.message.channel.id == channel) {
  91.                 if (reaction.emoji.name === yellowTeamEmoji) {
  92.                     await reaction.message.guild.members.cache.get(user.id).roles.remove(yellowTeamRole);
  93.                 }
  94.                 if (reaction.emoji.name === blueTeamEmoji) {
  95.                     await reaction.message.guild.members.cache.get(user.id).roles.remove(blueTeamRole);
  96.                 }
  97.             } else {
  98.                 return;
  99.             }
  100.         });
  101.     }
  102.  
  103. }  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement