index.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. const config = require('./config.json');
  2. const Discord = require('discord.js');
  3. const client = new Discord.Client({ partials: ['MESSAGE', 'CHANNEL', 'REACTION'] });
  4. client.on('messageReactionAdd', async (reaction, user) => {
  5. let serverData;
  6. config.reactions.forEach((el)=>{
  7. if (el.messageId == reaction.message.id && el.emojiId == reaction.emoji.id) {
  8. serverData = el;
  9. }
  10. });
  11. if (serverData == undefined) return;
  12. if (reaction.message.partial) await reaction.message.fetch();
  13. if (reaction.partial) await reaction.fetch();
  14. reaction.message.guild.members.fetch(user)
  15. .then((member) =>
  16. {
  17. member.roles.add(serverData.roleId);
  18. });
  19. });
  20. client.on('messageReactionRemove', async (reaction, user) => {
  21. let serverData;
  22. config.reactions.forEach((el)=>{
  23. if (el.messageId == reaction.message.id && el.emojiId == reaction.emoji.id) {
  24. serverData = el;
  25. }
  26. });
  27. if (serverData == undefined) return;
  28. if (reaction.message.partial) await reaction.message.fetch();
  29. if (reaction.partial) await reaction.fetch();
  30. reaction.message.guild.members.fetch(user)
  31. .then((member) =>
  32. {
  33. member.roles.remove(serverData.roleId);
  34. });
  35. });
  36. client.on('ready', () => {
  37. console.log(`Logged in as ${client.user.tag}!`);
  38. client.user.setActivity(config.activity);
  39. });
  40. client.login(config.token);