DudeThatsErin

reaction.js

Nov 22nd, 2020 (edited)
376
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const { ReactionRoleManager } = require('discord.js-collector');
  2. const { Client } = require("discord.js");
  3. const client = new Client();
  4. const {prefix, token} = require('../config.json');
  5.  
  6. const reactionRoleManager = new ReactionRoleManager(client, {
  7.     storage: true,
  8.     path: __dirname + './roles.json',
  9.     mongoDbLink: "mongodb://localhost:27017",
  10. });
  11.  
  12. client.on("ready", () => {
  13.     console.log("ready");
  14. });
  15.  
  16. // When is ready, reation role manager will emit this event
  17. reactionRoleManager.on('ready', () => {
  18.     console.log('Reaction Role Manager is ready!');
  19. });
  20.  
  21. // When user react and win role, will trigger this event
  22. reactionRoleManager.on('reactionRoleAdd', (member, role) => {
  23.     console.log(member.displayName + ' won the role' + role.name)
  24. });
  25.  
  26. // When user remove reaction and lose role, will trigger this event
  27. reactionRoleManager.on('reactionRoleRemove', (member, role) => {
  28.     console.log(member.displayName + ' lose the role' + role.name)
  29. });
  30.  
  31. // When someone removed all reactions from message
  32. reactionRoleManager.on('allReactionsRemove', (message) => {
  33.     console.log(`All reactions from message ${message.id} was removed, all roles was taken and reactions roles deleted.`)
  34. });
  35.  
  36. // If member doesn't have all requirements, this event is triggered.
  37. reactionRoleManager.on('missingRequirements', (type, member, reactionRole) => {
  38.     console.log(`Member '${member.id}' will not win role '${reactionRole.role}', because him hasn't requirement ${type}`);
  39. });
  40.  
  41. module.exports.run = async (client, message, args) => {
  42.        const role = message.mentions.roles.first();
  43.        if (!role)
  44.        return message
  45.        .reply(':x: You need mention a role')
  46.        .then((m) => m.delete({ timeout: 1_000 }));
  47.  
  48.        const emoji = args[1];
  49.        if (!emoji)
  50.            return message
  51.            .reply(':x: You need use a valid emoji.')
  52.            .then((m) => m.delete({ timeout: 1_000 }));
  53.  
  54.        const msg = await message.channel.messages.fetch(args[2] || message.id);
  55.        if (!role)
  56.            return message
  57.            .reply(':x: Message not found!')
  58.            .then((m) => m.delete({ timeout: 1_000 }));
  59.  
  60.        reactionRoleManager.addRole({
  61.            message: msg,
  62.            role,
  63.            emoji,
  64.        });
  65.        
  66.        message.reply(':white_check_mark: Done!').then((m) => m.delete({ timeout: 500 }));
  67.  
  68. }; // end module.exports
  69.  
  70. module.exports.help = {
  71.    name: 'createReactionRole',
  72.    description: 'Used to create reaction roles. You will need Discord Development Mode on to enable this functionality.',
  73.    aliases: ['crr', 'reactRole', 'CRR'],
  74.    usage: '.createReactionRole @role :emoji: MessageID',
  75.    inHelp: 'yes',
  76. }
RAW Paste Data