Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Require Packages
  2. const Discord = require('discord.js');
  3.  
  4. // Configure Packages
  5. const client = new Discord.Client();
  6. const prefix = '/'; // If you would like to add commands to the bot set this here
  7. const ownerID = '599334321450516500'; // Set your ID in here. Do it by copy and pasting it through discord.
  8. const active = new Map();
  9.  
  10. client.on("error", (e) => console.error(e));
  11.   client.on("warn", (e) => console.warn(e));
  12.   client.on("debug", (e) => console.info(e));
  13.  
  14.  
  15. client.on('ready', () => {
  16.     client.user.setGame('Kalo ada apa - apa DM bot INI');
  17.     console.log(`Bot has started, with ${client.users.size} users!`);
  18.  
  19.     });
  20.  
  21.   client.on("guildCreate", guild => {
  22.     // This event triggers when the bot joins a guild.
  23.     console.log(`${guild.name} SERVER JOINED (id: ${guild.id})! KEEP CAUTION!`);
  24.   });
  25.  
  26.   client.on("guildDelete", guild => {
  27.     // this event triggers when the bot is removed from a guild.
  28.     console.log(`I have been removed from: ${guild.name} (id: ${guild.id})`);
  29.   });
  30.  
  31.   const db = require('quick.db');
  32.  
  33. // Listener Events
  34. client.on('message', async message => {
  35.     if (message.author.bot) return;
  36.    
  37.     // Check if Message is in a DM
  38.     if (message.guild === null) {
  39.         // Fetch Activity Info
  40.         let active = await db.fetch(`support_${message.author.id}`);
  41.         let guild = client.guilds.get('628366230025273349'); // Your Server ID
  42.         let channel, found = true;
  43.         try {
  44.             if (active) client.channels.get(active.channelID).guild;
  45.         } catch(e) {
  46.             found = false;
  47.         }
  48.         if (!active || !found) {
  49.             // Create Support Channel.
  50.             active = {};
  51.             let modRoles = guild.roles.find("name", "Developer"); // Find the Mod/Admin roles so only Admin/Mods will see the tickets. Add it in the quotes
  52.             let everyone = guild.roles.find("name","@" + "everyone");
  53.             let bot = guild.roles.find("name","bot");
  54.             channel = await guild.createChannel(`${message.author.username}-${message.author.discriminator}`);
  55.                 channel.setParent('636942627606102027'); // Management Category ID
  56.                 channel.setTopic(`_complete to close the Ticket | ModMail for ${message.author.tag} | ID: ${message.author.id}`);
  57.                 channel.overwritePermissions(modRoles, {
  58.                     VIEW_CHANNEL: true,
  59.                     SEND_MESSAGES: true,
  60.                     MANAGE_CHANNELS: true
  61.                 });
  62.                 channel.overwritePermissions(everyone, {
  63.                     VIEW_CHANNEL: false,
  64.                 });
  65.                 channel.overwritePermissions(bot, {
  66.                     VIEW_CHANNEL: true,
  67.                     SEND_MESSAGES: true,
  68.                     MANAGE_CHANNELS: true
  69.                 }); // This will set the permissions so only Staff will see the ticket.
  70.             let author = message.author;
  71.             const newChannel = new Discord.RichEmbed()
  72.                 .setColor('36393E')
  73.                 .setAuthor(author.tag, author.displayAvatarURL)
  74.                 .setFooter('ModMail Ticket Created')
  75.                 .addField('User', author)
  76.                 .addField('ID', author.id);
  77.             await channel.send(newChannel);
  78.            
  79.             const newTicket = new Discord.RichEmbed()
  80.                 .setColor('36393E')
  81.                 .setAuthor(`Hello, ${author.tag}`, author.displayAvatarURL)
  82.                 .setFooter('ModMail Ticket Created');
  83.                
  84.             await author.send(newTicket);
  85.            
  86.             // Update Active Data
  87.             active.channelID = channel.id;
  88.             active.targetID = author.id;
  89.         }
  90.        
  91.         channel = client.channels.get(active.channelID);
  92.         const dm = new Discord.RichEmbed()
  93.             .setColor('36393E')
  94.             .setAuthor(`Thank you, ${message.author.tag}`, message.author.displayAvatarURL)
  95.             .setFooter(`Your message has been sent -- A staff member will be in contact soon.`);
  96.            
  97.         await message.author.send(dm);
  98.        
  99.         const embed = new Discord.RichEmbed()
  100.             .setColor('36393E')
  101.             .setAuthor(message.author.tag, message.author.displayAvatarURL)
  102.             .setDescription(message.content)
  103.             .setFooter(`Message Recieved -- ${message.author.tag}`);
  104.            
  105.         await channel.send(embed);
  106.         db.set(`support_${message.author.id}`, active);
  107.         db.set(`supportChannel_${channel.id}`, message.author.id);
  108.         return;
  109.     }
  110.    
  111.     let support = await db.fetch(`supportChannel_${message.channel.id}`);
  112.     if (support) {
  113.         support = await db.fetch(`support_${support}`);
  114.         let supportUser = client.users.get(support.targetID);
  115.         if (!supportUser) return message.channel.delete();
  116.        
  117.         // !complete command
  118.         if (message.content.toLowerCase() === "_complete") {
  119.             const complete = new Discord.RichEmbed()
  120.                 .setColor('36393E')
  121.                 .setAuthor(`Hey, ${supportUser.tag}`, supportUser.displayAvatarURL)
  122.                 .setFooter('Ticket Closed')
  123.                 .setDescription('*Your ModMail has been marked as **Complete**. If you wish to reopen this, or create a new one, please send a message to the bot.*');
  124.                
  125.             supportUser.send(complete);
  126.             message.channel.delete()
  127.                 .then(console.log(`Support for ${supportUser.tag} has been closed.`))
  128.                 .catch(console.error);
  129.             return db.delete(`support_${support.targetID}`);
  130.         }
  131.         const embed = new Discord.RichEmbed()
  132.             .setColor('36393E')
  133.             .setAuthor(message.author.tag, message.author.displayAvatarURL)
  134.             .setFooter(`Message Recieved`)
  135.             .setDescription(message.content);
  136.            
  137.         client.users.get(support.targetID).send(embed);
  138.         message.delete({timeout: 1000});
  139.         embed.setFooter(`Message Sent -- ${supportUser.tag}`).setDescription(message.content);
  140.         return message.channel.send(embed);
  141.     }
  142.  
  143.  
  144.   // Variables
  145.   let msg = message.content.toUpperCase(); // This takes the message.content, and turns it all uppercase.
  146.   let sender = message.author; // This variable holds the message's author.
  147.   let args = message.content.slice(prefix.length).trim().split(' '); // This variable takes the message.content, slices off the prefix from the front, then trims the blank spaces on the side, and turns it into an array by separating it by spaces.
  148.   let cmd = args.shift().toLowerCase(); // This variable holds the first item from the args array, which is taken off of the args array and turned into lowercase.
  149.  
  150.   // Return Statements
  151.   if (!msg.startsWith(prefix)) return; // If the message doesn't start with the prefix, exit the code.
  152.  
  153. })
  154.  
  155.  
  156. client.login("NjM3MzE1ODcyNjI4ODAxNTQ1.XbMZaw.G2s7AlwuQ2lFp6_Rr2wXUZ4VDVk"); //Add the token to your bot user here
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement