Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { Command } = require("../Structures/Command");
- const Bot = require("../index");
- const Discord = require("discord.js")
- module.exports = class MODMAILCOMMAND extends Command {
- constructor(bot) {
- super(bot)
- this.name = "modmail",
- this.description = "Modmail!",
- this.usage = "<prefix>create / stop",
- this.ownerOnly = false,
- this.aliases = ["create"],
- this.bot = bot;
- }
- async exec(message , member) {
- let messageArray = message.content.split(" ")
- let cmd = messageArray[0].toLowerCase();
- let args = messageArray.slice(1)
- let db = await this.bot.db.findOne({ where: { guild_id: message.guild.id } })
- if (db === null) {
- await this.bot.db.create({ guild_id: message.guild.id })
- }
- if (message.author.bot) return;
- if (cmd.toLowerCase() === `!create`) {
- message.guild.createChannel("modmail", "category")
- }
- let category = message.guild.channels.find(c => c.name == "modmail" && c.type == "category")
- if (message.channel.type !== `text`) {
- let active = await db.fetch(`support_${message.author.id}`);
- let guild = bot.guilds.get(`${category.id}`);
- let channel, found = true;
- try {
- if (active) bot.channels.get(active.channelID).guild;
- } catch (e) {
- found = false;
- }
- if (!active || !found) {
- active = {};
- channel = await guild.createChannel(`${message.author.username}-${message.author.discriminator}`, {
- parent: `662836369059479563`,
- topic: `!close to close the ticket | Support for ${message.author.tag} | ID: ${message.author.id}`,
- type: `text`
- });
- let author = message.author;
- const newChannel = new Discord.RichEmbed()
- .setColor(0xff6b6b)
- .setTitle(`__**New Modmail thread**__`)
- .addField(`User`, `${message.author}`)
- .addField(`ID`, `${message.author.id}`)
- .setFooter(`!close to close the thread!`, `${channel.guild.iconURL}`)
- .setTimestamp()
- .setThumbnail(`${message.author.displayAvatarURL}`)
- await channel.send(`@here`)
- await channel.send(newChannel)
- await author.send(`Thank you for your message! Our modmail team will reply to you here as soon as possible.`)
- active.channelID = channel.id;
- active.targetID = author.id;
- }
- channel = bot.channels.get(active.channelID);
- if (message.attachments.size !== 0) { // Attachments are present.
- const firstAttachment = message.attachments.first();
- const embed = new Discord.RichEmbed()
- .setAuthor(`${message.author.tag}`, `${message.author.displayAvatarURL}`)
- .setDescription(`${message.content}`)
- .setColor(0xff6b6b)
- .setTimestamp()
- .setImage(`${firstAttachment.url}`)
- .setFooter(`!help`)
- await channel.send(embed)
- }
- if (message.attachments.size === 0) { // Attachments are present.
- const embed = new Discord.RichEmbed()
- .setAuthor(`${message.author.tag}`, `${message.author.displayAvatarURL}`)
- .setDescription(`${message.content}`)
- .setColor(0xff6b6b)
- .setTimestamp()
- .setFooter(`!help`)
- await channel.send(embed)
- }
- db.set(`support_${message.author.id}`, active);
- db.set(`supportChannel_${channel.id}`, message.author.id);
- }
- let support = await db.get(`supportChannel_${message.channel.id}`);
- if (support) {
- support = await db.fetch(`support_${support}`);
- let supportUser = bot.users.get(support.targetID);
- if (!supportUser) return message.channel.delete();
- if (cmd.toLowerCase() === `!help`) {
- const help = new Discord.RichEmbed()
- .setAuthor(`${bot.user.username} commands!`, `${bot.user.displayAvatarURL}`)
- .setColor(0xff0000)
- .addField(`!help`, `Shows this message`)
- .addField(`!reply | !r`, `Replies to the modmail thread`)
- .addField(`!close | !end`, `Ends the modmail thread`)
- .setTimestamp()
- message.author.send(help)
- }
- if (cmd.toLowerCase() === `!close`) {
- supportUser.send(`Your ticket has been closed. Please do not hesitate to contact us again if you need further assistance.`);
- message.channel.delete();
- db.delete(`support_${support.targetID}`);
- }
- if (cmd.toLowerCase() === `!end`) {
- supportUser.send(`Your ticket has been closed. Please do not hesitate to contact us again if you need further assistance.`);
- message.channel.delete();
- db.delete(`support_${support.targetID}`);
- }
- if (cmd === `!r`) {
- let suggestion = args.slice(0).join(" ");
- if (message.attachments.size !== 0) { // Attachments are present.
- const firstAttachment = message.attachments.first();
- const embed = new Discord.RichEmbed()
- .setAuthor(`${message.author.tag}`, `${message.author.displayAvatarURL}`)
- .setDescription(`${suggestion}`)
- .setColor(0xff0000)
- .setImage(`${firstAttachment.url}`)
- .setTimestamp()
- .setFooter(`!help`)
- message.channel.send(embed)
- }
- if (message.attachments.size === 0) { // Attachments are present.
- const embed1 = new Discord.RichEmbed()
- .setAuthor(`${message.author.tag}`, `${message.author.displayAvatarURL}`)
- .setDescription(`${suggestion}`)
- .setColor(0xff0000)
- .setTimestamp()
- .setFooter(`!help`)
- message.channel.send(embed1)
- }
- if (message.attachments.size === 0) { // Attachments are present.
- bot.users.get(support.targetID).send(`**${message.author.username}:** ${suggestion}`)
- message.delete({ timeout: 1000 });
- }
- if (message.attachments.size !== 0) { // Attachments are present.
- const firstAttachment = message.attachments.first();
- bot.users.get(support.targetID).send(`**${message.author.username}:** ${suggestion}`)
- const embed3 = new Discord.RichEmbed()
- .setImage(`${firstAttachment.url}`)
- await bot.users.get(support.targetID).send(embed3)
- message.delete({ timeout: 1000 });
- }
- }
- if (cmd === `!reply`) {
- let suggestion = args.slice(0).join(" ");
- if (message.attachments.size !== 0) { // Attachments are present.
- const firstAttachment = message.attachments.first();
- const embed = new Discord.RichEmbed()
- .setAuthor(`${message.author.tag}`, `${message.author.displayAvatarURL}`)
- .setDescription(`${suggestion}`)
- .setColor(0xff0000)
- .setImage(`${firstAttachment.url}`)
- .setTimestamp()
- .setFooter(`!help`)
- message.channel.send(embed)
- }
- if (message.attachments.size === 0) { // Attachments are present.
- const embed1 = new Discord.RichEmbed()
- .setAuthor(`${message.author.tag}`, `${message.author.displayAvatarURL}`)
- .setDescription(`${suggestion}`)
- .setColor(0xff0000)
- .setTimestamp()
- .setFooter(`!help`)
- message.channel.send(embed1)
- }
- if (message.attachments.size === 0) { // Attachments are present.
- bot.users.get(support.targetID).send(`**${message.author.username}:** ${suggestion}`)
- message.delete({ timeout: 1000 });
- }
- if (message.attachments.size !== 0) { // Attachments are present.
- const firstAttachment = message.attachments.first();
- bot.users.get(support.targetID).send(`**${message.author.username}:** ${suggestion}`)
- const embed3 = new Discord.RichEmbed()
- .setImage(`${firstAttachment.url}`)
- await bot.users.get(support.targetID).send(embed3)
- message.delete({ timeout: 1000 })
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement