UndercoverNL

Raw Ticket

Sep 21st, 2020
908
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const events = {
  2.     MESSAGE_REACTION_ADD: 'messageReactionAdd',
  3.     MESSAGE_REACTION_REMOVE: 'messageReactionRemove',
  4. };
  5.  
  6. client.on('raw', async event => {
  7.  
  8.     if (!events.hasOwnProperty(event.t)) return;
  9.  
  10.     const { d: data } = event;
  11.     const user = client.users.get(data.user_id);
  12.     const channel = client.channels.get(data.channel_id) || await user.createDM();
  13.    
  14.     if (channel.messages.has(data.message_id)) return;
  15.    
  16.     const message = await channel.fetchMessage(data.message_id);
  17.    
  18.     const emojiKey = (data.emoji.id) ? `${data.emoji.name}:${data.emoji.id}` : data.emoji.name;
  19.     const reaction = message.reactions.get(emojiKey);
  20.  
  21.     client.emit(events[event.t], reaction, user);
  22.  
  23. });
  24.  
  25. client.on('messageReactionAdd', (reaction, user) => {
  26.      
  27. if (user.bot) return;
  28.      
  29. if(reaction.emoji == '💳'){
  30.   if(!reaction.message.channel.name.startsWith("💳l-tickets")) return;
  31.     reaction.remove(user.id);
  32.     let alreadyOpen = reaction.message.guild.channels.findKey(channel => channel.topic === `id: ${user.id}`);
  33.       if (alreadyOpen) {
  34.           return user.send("You already have a ticket open!")
  35.       }
  36.     let role = reaction.message.guild.roles.find(c => c.name ==='Ticket Helper');
  37.     let category = reaction.message.guild.channels.find(c => c.name == "tickets" && c.type == "category");
  38.     let role2 = reaction.message.guild.roles.find(c => c.name ==='@everyone');
  39.     reaction.message.guild.createChannel("?ticket-" + user.username, "text").then(c => {
  40.         c.overwritePermissions(role, {
  41.             SEND_MESSAGES: true,
  42.             READ_MESSAGES: true
  43.         });
  44.         c.overwritePermissions(role2, {
  45.             SEND_MESSAGES: false,
  46.             READ_MESSAGES: false,
  47.             ADD_REACTIONS: false
  48.         });
  49.         c.overwritePermissions(user, {
  50.             SEND_MESSAGES: true,
  51.             READ_MESSAGES: true
  52.         })
  53.        
  54.   c.setParent(category.id)
  55.   c.setTopic(`id: ${user.id}`)
  56.   let bicon = client.user.displayAvatarURL;
  57.   const ticketEmbed = new discord.RichEmbed()
  58.   .setTitle("Hallo " + user.username)
  59.   .setDescription(`Thank you for making a ticket! Our staff team will help you as soon as possible!`)
  60.   .setColor("#00ff00")
  61.   .setTimestamp()
  62.   .setFooter("Ticket created on:", bicon)
  63.   .setColor("#0080ff")
  64. .setThumbnail(reaction.message.guild.iconURL);
  65.  c.send(ticketEmbed);
  66.     })
  67.    
  68. }
  69.  
  70. });
RAW Paste Data