UNPKG

mpticket

Version:
127 lines (96 loc) • 4.9 kB
const Discord = require('discord.js') const { Client, Message } = require('discord.js') const fs = require('fs') /** * @param {string} message * @param {Client} client */ async function msg (message, client) { const { prefixstring, guildstring, sendmessagestring, categorystring, closetitlestring, sendadminstring, channelnoticketstring, createmsgtitlestring, createmsgdescstring, sendadminstringdesc, embebcolorstring } = require("../../../panel.json") const tuser = require('./tuser.json') const tchannel = require('./tchannel.json') if(message.author.bot) return; if(message.channel.type == "DM"){ if (tuser[message.author.id]) { message.react('👍') const embeb = new Discord.MessageEmbed() embeb.setAuthor(message.author.tag, message.author.displayAvatarURL()) embeb.setColor(embebcolorstring) embeb.setTitle(`${sendmessagestring} ${message.author.username}`) embeb.setDescription(`${message.content}`) client.guilds.cache.get(guildstring).channels.cache.get(tuser[message.author.id]).send({embeds: [embeb]}) } else { const create = new Discord.MessageEmbed() create.setAuthor(message.author.tag, message.author.displayAvatarURL()) create.setTitle(`${createmsgtitlestring}`) create.setColor(embebcolorstring) create.setDescription(`${createmsgdescstring}`) message.reply({ embeds: [create]}) client.guilds.cache.get(guildstring).channels.create(`ticket-${message.author.username}`).then(vchannel => { vchannel.setParent(categorystring) tuser[message.author.id] = vchannel.id fs.writeFile('./tuser.json', JSON.stringify(tuser), (err) => { if(err) console.log(err) }) tchannel[vchannel.id] = message.author.id fs.writeFile('./tchannel.json', JSON.stringify(tchannel), (err) => { if(err) console.log(err) }) const embeb = new Discord.MessageEmbed() embeb.setAuthor(message.author.tag, message.author.displayAvatarURL()) embeb.setColor(embebcolorstring) embeb.setTitle(`${createmsgtitlestring} ${message.author.username}`) embeb.setDescription(`${message.content}`) vchannel.send({embeds: [embeb]}) }) } }; if(message.content === prefixstring + "close"){ if(!message.guildId === guildstring) return; if (message.channel.type == "dm") return; try { const ticketid = tchannel[message.channel.id] const noticket = new Discord.MessageEmbed() noticket.setAuthor(message.author.tag, message.author.displayAvatarURL()) noticket.setColor('#ff0000') noticket.setTitle(`${channelnoticketstring}`) if(ticketid === undefined) return message.reply({ embeds: [noticket] }); const réponsrmbrb = new Discord.MessageEmbed() .setAuthor(message.author.tag, message.author.displayAvatarURL()) .setColor(`#303136`) .setTitle(`${closetitlestring}`) client.guilds.cache.get(guildstring).channels.cache.get(message.channelId).delete(); client.users.cache.get(`${ticketid}`).send({embeds: [réponsrmbrb]}) } catch (e) { const errorEmbed = new Discord.MessageEmbed() .setColor("RED") .setDescription(`⛔ Alert: ${e}`) return message.reply({embeds: [errorEmbed]}); } } if(!message.guildId === guildstring) return; if(message.content === prefixstring + "close") return; try { const ticketid = tchannel[message.channel.id] if(ticketid === undefined) return; const repembeb = new Discord.MessageEmbed() .setAuthor(message.author.tag, message.author.displayAvatarURL()) .setColor(embebcolorstring) .setTitle(`${sendadminstring}`) .setDescription(`__${sendadminstringdesc} :__ ${message.content}`) const réponsrmbrb = new Discord.MessageEmbed() .setAuthor(message.author.tag, message.author.displayAvatarURL()) .setColor(embebcolorstring) .setTitle(`${sendmessagestring} ${message.author.username}`) .setDescription(`${message.content}`) client.users.cache.get(`${ticketid}`).send({ embeds: [réponsrmbrb]}) message.reply({ embeds: [repembeb]}) } catch (e) { const errorEmbed = new Discord.MessageEmbed() .setColor("RED") .setDescription(`⛔ Alert: ${e}`) return message.reply({embeds: [errorEmbed]}); } } module.exports = msg