Danulsan

Untitled

Jun 26th, 2023
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. const { Client, GatewayIntentBits, EmbedBuilder, PermissionsBitField, Permissions, MessageManager, Embed, Collection, Events } = require(`discord.js`);
  2. const fs = require('fs');
  3. const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] });
  4. const reactions = require('./Schemas.js/reactionjs');
  5.  
  6. client.commands = new Collection();
  7.  
  8. require('dotenv').config();
  9.  
  10. const functions = fs.readdirSync("./src/functions").filter(file => file.endsWith(".js"));
  11. const eventFiles = fs.readdirSync("./src/events").filter(file => file.endsWith(".js"));
  12. const commandFolders = fs.readdirSync("./src/commands");
  13.  
  14. (async () => {
  15. for (file of functions) {
  16. require(`./functions/${file}`)(client);
  17. }
  18. client.handleEvents(eventFiles, "./src/events");
  19. client.handleCommands(commandFolders, "./src/commands");
  20. client.login(process.env.token)
  21. })();
  22.  
  23. client.on(Events.MessageReactionAdd, async (reaction, user) => {
  24. if (!reaction.message.guildId) return;
  25. if (user.bot) return
  26.  
  27. let cID = `<:${reaction.emoji.name}:${reaction.reaction.id}>`;
  28. if (!reaction.emoji.id) cID = reaction.emoji.name;
  29.  
  30. const data = await reactions.findOne({ Guild: reaction.message.guildId, Message: reaction.message.id, Emoji: cID });
  31.  
  32. if (!data) return;
  33.  
  34. const guild = await client.guilds.cache.get(reaction.message.guildId);
  35. const member = await guild.members.cache.get(user.id)
  36.  
  37. try {
  38. await member.roles.add(data.Role);
  39. } catch (e) {
  40. return;
  41. }
  42. });
  43.  
  44.  
  45.  
  46.  
  47. client.on(Events.MessageReactionRemove, async (reaction, user) => {
  48. if (!reaction.message.guildId) return;
  49. if (user.bot) return
  50.  
  51. let cID = `<:${reaction.emoji.name}:${reaction.reaction.id}>`;
  52. if (!reaction.emoji.id) cID = reaction.emoji.name;
  53.  
  54. const data = await reactions.findOne({ Guild: reaction.message.guildId, Message: reaction.message.id, Emoji: cID });
  55.  
  56. if (!data) return;
  57.  
  58. const guild = await client.guilds.cache.get(reaction.message.guildId);
  59. const member = await guild.members.cache.get(user.id)
  60.  
  61. try {
  62. await member.roles.remove(data.Role);
  63. } catch (e) {
  64. return;
  65. }
  66. });
  67.  
Add Comment
Please, Sign In to add comment