SHARE
TWEET

find error

a guest Jan 24th, 2020 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const { Command } = require("../Structures/Command");
  2. const Discord = require("discord.js")
  3. module.exports = class MODMAILCOMMAND extends Command {
  4.  
  5.   constructor(bot) {
  6.     super(bot)
  7.     this.name = "modmail",
  8.       this.description = "Modmail!",
  9.       this.usage = "<prefix>create / stop",
  10.       this.ownerOnly = false,
  11.       this.aliases = ["create"],
  12.       this.bot = bot;
  13.   }
  14.  
  15.   async exec(message) {
  16.  
  17.     let messageArray = message.content.split(" ")
  18.     let cmd = messageArray[0].toLowerCase();
  19.     let args = messageArray.slice(1)
  20.     let guild = message.guild.id
  21.  
  22.     if (message.author.bot) return;
  23.  
  24.     if (cmd.toLowerCase() === `!create`) {
  25.  
  26.         message.guild.createChannel("modmail", "category")
  27.  
  28.     }
  29.  
  30.     let category = guild.channels.find(c => c.name == "modmail" && c.type == "category")
  31.  
  32.     if (message.channel.type !== `text`) {
  33.  
  34.         let active = await db.fetch(`support_${message.author.id}`);
  35.         let guild = bot.guilds.get(`${category.id}`);
  36.         let channel, found = true;
  37.  
  38.         try {
  39.             if (active) bot.channels.get(active.channelID).guild;
  40.         } catch (e) {
  41.             found = false;
  42.         }
  43.  
  44.         if (!active || !found) {
  45.  
  46.             active = {};
  47.  
  48.             channel = await guild.createChannel(`${message.author.username}-${message.author.discriminator}`, {
  49.                 parent: `662836369059479563`,
  50.                 topic: `!close to close the ticket | Support for ${message.author.tag} | ID: ${message.author.id}`,
  51.                 type: `text`
  52.             });
  53.  
  54.             let author = message.author;
  55.  
  56.             const newChannel = new Discord.RichEmbed()
  57.                 .setColor(0xff6b6b)
  58.                 .setTitle(`__**New Modmail thread**__`)
  59.                 .addField(`User`, `${message.author}`)
  60.                 .addField(`ID`, `${message.author.id}`)
  61.                 .setFooter(`!close to close the thread!`, `${channel.guild.iconURL}`)
  62.                 .setTimestamp()
  63.                 .setThumbnail(`${message.author.displayAvatarURL}`)
  64.             await channel.send(`@here`)
  65.             await channel.send(newChannel)
  66.             await author.send(`Thank you for your message! Our modmail team will reply to you here as soon as possible.`)
  67.  
  68.             active.channelID = channel.id;
  69.             active.targetID = author.id;
  70.  
  71.  
  72.         }
  73.  
  74.         channel = bot.channels.get(active.channelID);
  75.  
  76.         if (message.attachments.size !== 0) { // Attachments are present.
  77.             const firstAttachment = message.attachments.first();
  78.  
  79.  
  80.             const embed = new Discord.RichEmbed()
  81.                 .setAuthor(`${message.author.tag}`, `${message.author.displayAvatarURL}`)
  82.                 .setDescription(`${message.content}`)
  83.                 .setColor(0xff6b6b)
  84.                 .setTimestamp()
  85.                 .setImage(`${firstAttachment.url}`)
  86.                 .setFooter(`!help`)
  87.  
  88.             await channel.send(embed)
  89.  
  90.         }
  91.        
  92.  
  93.         if (message.attachments.size === 0) { // Attachments are present.
  94.  
  95.             const embed = new Discord.RichEmbed()
  96.                 .setAuthor(`${message.author.tag}`, `${message.author.displayAvatarURL}`)
  97.                 .setDescription(`${message.content}`)
  98.                 .setColor(0xff6b6b)
  99.                 .setTimestamp()
  100.                 .setFooter(`!help`)
  101.  
  102.             await channel.send(embed)
  103.  
  104.         }
  105.  
  106.         db.set(`support_${message.author.id}`, active);
  107.         db.set(`supportChannel_${channel.id}`, message.author.id);
  108.     }
  109.  
  110.     let support = await db.fetch(`supportChannel_${message.channel.id}`);
  111.  
  112.     if (support) {
  113.  
  114.         support = await db.fetch(`support_${support}`);
  115.  
  116.         let supportUser = bot.users.get(support.targetID);
  117.         if (!supportUser) return message.channel.delete();
  118.  
  119.         if (cmd.toLowerCase() === `!help`) {
  120.  
  121.             const help = new Discord.RichEmbed()
  122.                 .setAuthor(`${bot.user.username} commands!`, `${bot.user.displayAvatarURL}`)
  123.                 .setColor(0xff0000)
  124.                 .addField(`!help`, `Shows this message`)
  125.                 .addField(`!reply | !r`, `Replies to the modmail thread`)
  126.                 .addField(`!close | !end`, `Ends the modmail thread`)
  127.                 .setTimestamp()
  128.  
  129.             message.author.send(help)
  130.  
  131.         }
  132.  
  133.         if (cmd.toLowerCase() === `!close`) {
  134.  
  135.             supportUser.send(`Your ticket has been closed. Please do not hesitate to contact us again if you need further assistance.`);
  136.  
  137.             message.channel.delete();
  138.  
  139.             db.delete(`support_${support.targetID}`);
  140.  
  141.         }
  142.  
  143.         if (cmd.toLowerCase() === `!end`) {
  144.  
  145.             supportUser.send(`Your ticket has been closed. Please do not hesitate to contact us again if you need further assistance.`);
  146.  
  147.             message.channel.delete();
  148.  
  149.             db.delete(`support_${support.targetID}`);
  150.  
  151.         }
  152.  
  153.         if (cmd === `!r`) {
  154.  
  155.             let suggestion = args.slice(0).join(" ");
  156.  
  157.             if (message.attachments.size !== 0) { // Attachments are present.
  158.                 const firstAttachment = message.attachments.first();
  159.  
  160.                 const embed = new Discord.RichEmbed()
  161.                     .setAuthor(`${message.author.tag}`, `${message.author.displayAvatarURL}`)
  162.                     .setDescription(`${suggestion}`)
  163.                     .setColor(0xff0000)
  164.                     .setImage(`${firstAttachment.url}`)
  165.                     .setTimestamp()
  166.                     .setFooter(`!help`)
  167.                 message.channel.send(embed)
  168.             }
  169.  
  170.             if (message.attachments.size === 0) { // Attachments are present.
  171.  
  172.                 const embed1 = new Discord.RichEmbed()
  173.                     .setAuthor(`${message.author.tag}`, `${message.author.displayAvatarURL}`)
  174.                     .setDescription(`${suggestion}`)
  175.                     .setColor(0xff0000)
  176.                     .setTimestamp()
  177.                     .setFooter(`!help`)
  178.                 message.channel.send(embed1)
  179.             }
  180.  
  181.             if (message.attachments.size === 0) { // Attachments are present.
  182.                 bot.users.get(support.targetID).send(`**${message.author.username}:** ${suggestion}`)
  183.                 message.delete({ timeout: 1000 });
  184.             }
  185.  
  186.             if (message.attachments.size !== 0) { // Attachments are present.
  187.                 const firstAttachment = message.attachments.first();
  188.                 bot.users.get(support.targetID).send(`**${message.author.username}:** ${suggestion}`)
  189.  
  190.                 const embed3 = new Discord.RichEmbed()
  191.                     .setImage(`${firstAttachment.url}`)
  192.                 await bot.users.get(support.targetID).send(embed3)
  193.  
  194.                 message.delete({ timeout: 1000 });
  195.             }
  196.  
  197.         }
  198.  
  199.         if (cmd === `!reply`) {
  200.  
  201.             let suggestion = args.slice(0).join(" ");
  202.  
  203.  
  204.             if (message.attachments.size !== 0) { // Attachments are present.
  205.                 const firstAttachment = message.attachments.first();
  206.  
  207.                 const embed = new Discord.RichEmbed()
  208.                     .setAuthor(`${message.author.tag}`, `${message.author.displayAvatarURL}`)
  209.                     .setDescription(`${suggestion}`)
  210.                     .setColor(0xff0000)
  211.                     .setImage(`${firstAttachment.url}`)
  212.                     .setTimestamp()
  213.                     .setFooter(`!help`)
  214.                 message.channel.send(embed)
  215.             }
  216.  
  217.             if (message.attachments.size === 0) { // Attachments are present.
  218.  
  219.                 const embed1 = new Discord.RichEmbed()
  220.                     .setAuthor(`${message.author.tag}`, `${message.author.displayAvatarURL}`)
  221.                     .setDescription(`${suggestion}`)
  222.                     .setColor(0xff0000)
  223.                     .setTimestamp()
  224.                     .setFooter(`!help`)
  225.                 message.channel.send(embed1)
  226.             }
  227.  
  228.             if (message.attachments.size === 0) { // Attachments are present.
  229.                 bot.users.get(support.targetID).send(`**${message.author.username}:** ${suggestion}`)
  230.                 message.delete({ timeout: 1000 });
  231.             }
  232.  
  233.             if (message.attachments.size !== 0) { // Attachments are present.
  234.                 const firstAttachment = message.attachments.first();
  235.                 bot.users.get(support.targetID).send(`**${message.author.username}:** ${suggestion}`)
  236.  
  237.                 const embed3 = new Discord.RichEmbed()
  238.                     .setImage(`${firstAttachment.url}`)
  239.                 await bot.users.get(support.targetID).send(embed3)
  240.  
  241.                 message.delete({ timeout: 1000 })
  242.  
  243.             }
  244.  
  245.         }
  246.  
  247.     }
  248.  
  249.   }
  250.  
  251. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top