Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. const Discord = require("discord.js");
  2. const tickets = require("../tickets.json");
  3. const fs = require("fs");
  4. const yml = require("../yml.js");
  5. module.exports.run = async (bot, message, args) => {
  6. let config = await yml("./config.yml");
  7. let role = message.guild.roles.find(r => r.name.toLowerCase() === config.Ticket_Support_Role.toLowerCase());
  8. let id = message.channel.name.split("-")[1];
  9. let find = tickets.find(t => t && t.id === id);
  10. let hasPermission = role ? message.member.roles.sort((a, b) => b.calculatedPosition - a.calculatedPosition).first().calculatedPosition >= role.calculatedPosition : undefined;
  11. if (role && !hasPermission && find.authorID !== message.author.id)
  12. return message.reply("You do not have permission for that command!");
  13. if (!role) message.reply("``ERROR!`` I could not find the ``" + config.Ticket_Support_Role + "`` role in this guild, please contact an administrator!");
  14. if (!role && !message.member.hasPermission("ADMINISTRATOR"))
  15. return message.reply("You do not have permission for that command!");
  16. let check = new RegExp("([a-z]|[A-Z])+[-]([0-9])+");
  17. let c = check.exec(message.channel.name);
  18. if (!c) return message.reply("You are not in a ticket channel!");
  19. if (!find) return message.reply("``ERROR!`` I could not find that ticket in the database!");
  20. tickets.splice(tickets.indexOf(find), 1);
  21. message.channel.delete();
  22. let channel = message.guild.channels.find(ch => ch.name.toLowerCase() === "ticket-log");
  23. let user = message.guild.member(find.authorID);
  24. if (channel) {
  25. let embed = new Discord.RichEmbed()
  26. .setThumbnail(bot.user.avatarURL)
  27. .setFooter("Tickets")
  28. .setAuthor("Ticket Closed")
  29. .setColor(config.New_Ticket_Embed_Color)
  30. .setDescription(`**Closed by:** ${message.author} **with ID:** ${message.author.id}\n**Creator:** ${user} **with ID:** ${find.authorID}\n**Ticket ID:** ${find.id}\n**Channel Name:** ${find.name}-${find.id}\n**Added Users:** ${find.addedUsers.join(",")}`);
  31. channel.send(embed);
  32. }
  33. let role2 = message.guild.roles.find("name", `ticket-${find.id}`);
  34. if (role2) {
  35. message.member.removeRole(role2.id);
  36. role2.delete();
  37. }
  38. fs.writeFile("./tickets.json", JSON.stringify(tickets), (err) => {
  39. if (err) console.log(err)
  40. })
  41. };
  42.  
  43. module.exports.help = {
  44. name: "close"
  45. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement