Advertisement
Guest User

Untitled

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