SHARE
TWEET

Untitled

a guest Apr 23rd, 2019 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const yourID = "ACA TU ID";
  2. const setupCMD = "g!confirmar"
  3. const initialMessage = `**React to the messages below to receive the associated role. If you would like to remove the role, simply remove your
  4.  
  5. reaction!**`;
  6. const embedMessage = `Para poder ver todo contenido debes reaccionar segun la que elijas se te dara uno de dos rangos user spain o user inglish
  7.  
  8. selecciona solo 1!`;
  9. const embedFooter = "Role Reactions";
  10. const roles = ["AQUI EL NOMBRE DEL RANGO"];
  11. const reactions = ["AQUI UN EMOJI PARA QUE REACCIONEN LOS USUARIOS"];
  12. const embed = true;
  13. const embedColor = "#dd2423";
  14. const botToken = "ACA EL TOKEN DE TU BOT";
  15.  
  16.  
  17. const { Client, RichEmbed } = require('discord.js');
  18. //const client = new Client({ disableEveryone: true });
  19. client.login(botToken);
  20.  
  21. // If there isn't a reaction for every role, scold the user!
  22. if (roles.length !== reactions.length) throw "Roles list and reactions list are not the same length!";
  23.  
  24.  
  25. function generateMessages() {
  26.     let messages = [];
  27.     for (let role of roles) messages.push(`React below to get the **"${role}"** role!`); //DONT CHANGE THIS
  28.     return messages;
  29. }
  30.  
  31.  
  32. function generateEmbedFields() {
  33.     return roles.map((r, e) => {
  34.         return {
  35.             emoji: reactions[e],
  36.             role: r
  37.         };
  38.     });
  39. }
  40. client.on("ready", () => console.log("Bot is online!"));
  41. client.on('error', console.error);
  42.  
  43.  
  44. client.on("message", message => {
  45.     if (message.author.id == yourID && message.content.toLowerCase() == setupCMD) {
  46.  
  47.         if (!embed) {
  48.             message.channel.send(initialMessage);
  49.  
  50.             const toSend = generateMessages();
  51.             toSend.forEach((role, react) => {
  52.                 message.channel.send(role).then(m => {
  53.                     m.react(reactions[react]);
  54.                 });
  55.             });
  56.         } else {
  57.             const roleEmbed = new RichEmbed()
  58.                 .setDescription(embedMessage)
  59.                 .setFooter(embedFooter);
  60.  
  61.             if (embedColor) roleEmbed.setColor(embedColor);
  62.  
  63.             const fields = generateEmbedFields();
  64.             for (const f of fields) roleEmbed.addField(f.emoji, f.role, true);
  65.  
  66.             message.channel.send(roleEmbed).then(async m => {
  67.                 for (let r of reactions) await m.react(r);
  68.             });
  69.         }
  70.     }
  71. });
  72.  
  73.  
  74. const events = {
  75.     MESSAGE_REACTION_ADD: 'messageReactionAdd',
  76.     MESSAGE_REACTION_REMOVE: 'messageReactionRemove',
  77. };
  78.  
  79.  
  80. client.on('raw', async event => {
  81.  
  82.     if (!events.hasOwnProperty(event.t)) return;
  83.  
  84.     const { d: data } = event;
  85.     const user = client.users.get(data.user_id);
  86.     const channel = client.channels.get(data.channel_id);
  87.  
  88.     const message = await channel.fetchMessage(data.message_id);
  89.     const member = message.guild.members.get(user.id);
  90.  
  91.     const emojiKey = (data.emoji.id) ? `${data.emoji.name}:${data.emoji.id}` : data.emoji.name;
  92.     const reaction = message.reactions.get(emojiKey);
  93.  
  94.     let embedFooterText;
  95.     if (message.embeds[0]) embedFooterText = message.embeds[0].footer.text;
  96.  
  97.     if (message.author.id === client.user.id && (message.content !== initialMessage || (message.embeds[0] && (embedFooterText !== embedFooter)))) {
  98.  
  99.         if (!embed) {
  100.             const re = `\\*\\*"(.+)?(?="\\*\\*)`;
  101.             const role = message.content.match(re)[1];
  102.  
  103.             if (member.id !== client.user.id) {
  104.                 const roleObj = message.guild.roles.find(r => r.name === role);
  105.  
  106.                 if (event.t === "MESSAGE_REACTION_ADD") {
  107.                     member.addRole(roleObj.id);
  108.                 } else {
  109.                     member.removeRole(roleObj.id);
  110.                 }
  111.             }
  112.         } else {
  113.             const fields = message.embeds[0].fields;
  114.  
  115.             for (let i = 0; i < fields.length; i++) {
  116.                 if (member.id !== client.user.id) {
  117.                     const role = message.guild.roles.find(r => r.name === fields[i].value);
  118.  
  119.                     if (fields[i].name === reaction.emoji.name) {
  120.                         if (event.t === "MESSAGE_REACTION_ADD") {
  121.                             member.addRole(role.id);
  122.                             break;
  123.                         } else {
  124.                             member.removeRole(role.id);
  125.                             break;
  126.                         }
  127.                     }
  128.                 }
  129.             }
  130.         }
  131.     }
  132. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top