From 33e4d97be5da1a478ce9438934722fda555e5c4f Mon Sep 17 00:00:00 2001 From: Noah Date: Sat, 23 Oct 2021 20:04:02 -0500 Subject: [PATCH] Updated for slash commands --- Addons/hello.js | 35 ++- Commands/TicketAdd.js | 130 +++++---- Commands/TicketRemove.js | 130 +++++---- Commands/closeticket.js | 343 ++++++++++++++---------- Commands/help.js | 155 ++++++----- Commands/info.js | 52 ++-- commands/ping.js | 36 +-- commands/ticket.js | 566 +++++++++++++++++++++++---------------- 8 files changed, 834 insertions(+), 613 deletions(-) diff --git a/Addons/hello.js b/Addons/hello.js index cd1ca34..4263449 100644 --- a/Addons/hello.js +++ b/Addons/hello.js @@ -4,9 +4,9 @@ const fs = require("fs"); const Discord = require("discord.js"); -const yaml = require('js-yaml'); -const supportbot = yaml.load(fs.readFileSync('./Data/supportbot.yml', 'utf8')); -const cmdconfig = yaml.load(fs.readFileSync('./Data/commands.yml', 'utf8')); +const yaml = require("js-yaml"); +const supportbot = yaml.load(fs.readFileSync("./Data/supportbot.yml", "utf8")); +const cmdconfig = yaml.load(fs.readFileSync("./Data/commands.yml", "utf8")); // Your Addon Config file! Saved in /Addons/Settings/YourAddonConig.yml // const exampleaddon = yaml.load(fs.readFileSync('./Addons/Settings/YourAddonConig.yml', 'utf8')); @@ -14,21 +14,18 @@ const cmdconfig = yaml.load(fs.readFileSync('./Data/commands.yml', 'utf8')); const Command = require("../Structures/Command.js"); module.exports = new Command({ - name: "hello", - description: "hello", - type: "BOTH", - slashCommandOptions: [], - permission: "SEND_MESSAGES", + name: "hello", + description: "hello", + slashCommandOptions: [], + permission: "SEND_MESSAGES", - async run(message, args, client) { + async run(interaction) { + const Embed = new Discord.MessageEmbed() + .setDescription("Hello World!") + .setColor(supportbot.InfoColour); - const Embed = new Discord.MessageEmbed() - .setDescription("Hello World!") - .setColor(supportbot.InfoColour) - - message.channel.send({ - embeds: [Embed] - }) - - } -}); \ No newline at end of file + interaction.reply({ + embeds: [Embed], + }); + }, +}); diff --git a/Commands/TicketAdd.js b/Commands/TicketAdd.js index cf85f2b..e02ff19 100644 --- a/Commands/TicketAdd.js +++ b/Commands/TicketAdd.js @@ -4,72 +4,92 @@ const fs = require("fs"); const Discord = require("discord.js"); -const yaml = require('js-yaml'); -const supportbot = yaml.load(fs.readFileSync('./Data/supportbot.yml', 'utf8')); -const cmdconfig = yaml.load(fs.readFileSync('./Data/commands.yml', 'utf8')); +const yaml = require("js-yaml"); +const supportbot = yaml.load(fs.readFileSync("./Data/supportbot.yml", "utf8")); +const cmdconfig = yaml.load(fs.readFileSync("./Data/commands.yml", "utf8")); const Command = require("../Structures/Command.js"); async function asyncForEach(array, callback) { - for (let index = 0; index < array.length; index++) { - await callback(array[index], index, array); - } + for (let index = 0; index < array.length; index++) { + await callback(array[index], index, array); } +} module.exports = new Command({ - name: cmdconfig.TicketAdd, - description: cmdconfig.TicketAddDesc, - type: "BOTH", - slashCommandOptions: [], - permission: "SEND_MESSAGES", + name: cmdconfig.TicketAdd, + description: cmdconfig.TicketAddDesc, + slashCommandOptions: [ + { + name: "user", + description: "User to add", + type: "USER", + required: true, + }, + ], + permission: "SEND_MESSAGES", - async run(message, args, client) { + async run(interaction) { + let SupportStaff = + interaction.guild.roles.cache.find( + (SupportTeam) => SupportTeam.name === supportbot.Staff + ) || + interaction.guild.roles.cache.find( + (SupportTeam) => SupportTeam.id === supportbot.Staff + ); + let Admins = + interaction.guild.roles.cache.find( + (AdminUser) => AdminUser.name === supportbot.Admin + ) || + interaction.guild.roles.cache.find( + (AdminUser) => AdminUser.id === supportbot.Admin + ); - let SupportStaff = message.guild.roles.cache.find(SupportTeam => SupportTeam.name === supportbot.Staff) || message.guild.roles.cache.find(SupportTeam => SupportTeam.id === supportbot.Staff) - let Admins = message.guild.roles.cache.find(AdminUser => AdminUser.name === supportbot.Admin) || message.guild.roles.cache.find(AdminUser => AdminUser.id === supportbot.Admin) + const NoPerms = new Discord.MessageEmbed() + .setTitle("Invalid Permissions!") + .setDescription( + `${supportbot.IncorrectPerms}\n\nRole Required: \`${supportbot.Staff}\` or \`${supportbot.Admin}\`` + ) + .setColor(supportbot.WarningColour); - const NoPerms = new Discord.MessageEmbed() - .setTitle("Invalid Permissions!") - .setDescription(`${supportbot.IncorrectPerms}\n\nRole Required: \`${supportbot.Staff}\` or \`${supportbot.Admin}\``) - .setColor(supportbot.WarningColour) + if ( + interaction.member.roles.cache.has(SupportStaff.id) || + interaction.member.roles.cache.has(Admins.id) + ) { + if ( + !interaction.channel.name.startsWith(`${supportbot.TicketChannel}-`) + ) { + const Exists = new Discord.MessageEmbed() + .setTitle("No Ticket Found!") + .setDescription(`${supportbot.NoValidTicket}`) + .setColor(supportbot.WarningColour); + return interaction.reply({ embeds: [Exists] }); + } - if (message.member.roles.cache.has(SupportStaff.id) || message.member.roles.cache.has(Admins.id)) { - if (!message.channel.name.startsWith( `${supportbot.TicketChannel}-` )) { - const Exists = new Discord.MessageEmbed() - .setTitle("No Ticket Found!") - .setDescription(`${supportbot.NoValidTicket}`) - .setColor(supportbot.WarningColour); - message.channel.send({ embeds: [Exists] }); - - return; - } - - let uMember = message.mentions.users.first(); - const UserNotExist = new Discord.MessageEmbed() - .setTitle("User Not Found!") - .setDescription(`${supportbot.UserNotFound}\n\nTry Again:\`${supportbot.Prefix}${cmdconfig.TicketAdd} \``) - .setColor(supportbot.ErrorColour) - - if (!uMember) return message.channel.send({ embeds: [UserNotExist] }); - - message.channel.permissionOverwrites.edit(uMember, { - VIEW_CHANNEL: true, - READ_MESSAGE_HISTORY: true, - SEND_MESSAGES: true, - }); - - const Complete = new Discord.MessageEmbed() - .setTitle("User Added!") - .setDescription(supportbot.AddedUser.replace(/%user%/g, uMember.id)) - .setTimestamp() - .setColor(supportbot.EmbedColour) - message.channel.send({ embeds: [Complete] }); - } else { - - return message.channel.send({ embeds: [NoPerms] }); + let uMember = interaction.options.getUser("user"); + const UserNotExist = new Discord.MessageEmbed() + .setTitle("User Not Found!") + .setDescription( + `${supportbot.UserNotFound}\n\nTry Again:\`${supportbot.Prefix}${cmdconfig.TicketAdd} \`` + ) + .setColor(supportbot.ErrorColour); - } + if (!uMember) return interaction.reply({ embeds: [UserNotExist] }); + interaction.channel.permissionOverwrites.edit(uMember, { + VIEW_CHANNEL: true, + READ_MESSAGE_HISTORY: true, + SEND_MESSAGES: true, + }); + + const Complete = new Discord.MessageEmbed() + .setTitle("User Added!") + .setDescription(supportbot.AddedUser.replace(/%user%/g, uMember.id)) + .setTimestamp() + .setColor(supportbot.EmbedColour); + interaction.reply({ embeds: [Complete] }); + } else { + return interaction.reply({ embeds: [NoPerms] }); } - -}); \ No newline at end of file + }, +}); diff --git a/Commands/TicketRemove.js b/Commands/TicketRemove.js index aea45c1..8b41e89 100644 --- a/Commands/TicketRemove.js +++ b/Commands/TicketRemove.js @@ -4,72 +4,92 @@ const fs = require("fs"); const Discord = require("discord.js"); -const yaml = require('js-yaml'); -const supportbot = yaml.load(fs.readFileSync('./Data/supportbot.yml', 'utf8')); -const cmdconfig = yaml.load(fs.readFileSync('./Data/commands.yml', 'utf8')); +const yaml = require("js-yaml"); +const supportbot = yaml.load(fs.readFileSync("./Data/supportbot.yml", "utf8")); +const cmdconfig = yaml.load(fs.readFileSync("./Data/commands.yml", "utf8")); const Command = require("../Structures/Command.js"); async function asyncForEach(array, callback) { - for (let index = 0; index < array.length; index++) { - await callback(array[index], index, array); - } + for (let index = 0; index < array.length; index++) { + await callback(array[index], index, array); } +} module.exports = new Command({ - name: cmdconfig.TicketRemove, - description: cmdconfig.TicketRemoveDesc, - type: "BOTH", - slashCommandOptions: [], - permission: "SEND_MESSAGES", + name: cmdconfig.TicketRemove, + description: cmdconfig.TicketRemoveDesc, + slashCommandOptions: [ + { + name: "user", + description: "User to remove", + type: "USER", + required: true, + }, + ], + permission: "SEND_MESSAGES", - async run(message, args, client) { + async run(interaction) { + let SupportStaff = + interaction.guild.roles.cache.find( + (SupportTeam) => SupportTeam.name === supportbot.Staff + ) || + interaction.guild.roles.cache.find( + (SupportTeam) => SupportTeam.id === supportbot.Staff + ); + let Admins = + interaction.guild.roles.cache.find( + (AdminUser) => AdminUser.name === supportbot.Admin + ) || + interaction.guild.roles.cache.find( + (AdminUser) => AdminUser.id === supportbot.Admin + ); - let SupportStaff = message.guild.roles.cache.find(SupportTeam => SupportTeam.name === supportbot.Staff) || message.guild.roles.cache.find(SupportTeam => SupportTeam.id === supportbot.Staff) - let Admins = message.guild.roles.cache.find(AdminUser => AdminUser.name === supportbot.Admin) || message.guild.roles.cache.find(AdminUser => AdminUser.id === supportbot.Admin) + const NoPerms = new Discord.MessageEmbed() + .setTitle("Invalid Permissions!") + .setDescription( + `${supportbot.IncorrectPerms}\n\nRole Required: \`${supportbot.Staff}\` or \`${supportbot.Admin}\`` + ) + .setColor(supportbot.WarningColour); - const NoPerms = new Discord.MessageEmbed() - .setTitle("Invalid Permissions!") - .setDescription(`${supportbot.IncorrectPerms}\n\nRole Required: \`${supportbot.Staff}\` or \`${supportbot.Admin}\``) - .setColor(supportbot.WarningColour) + if ( + interaction.member.roles.cache.has(SupportStaff.id) || + interaction.member.roles.cache.has(Admins.id) + ) { + if ( + !interaction.channel.name.startsWith(`${supportbot.TicketChannel}-`) + ) { + const Exists = new Discord.MessageEmbed() + .setTitle("No Ticket Found!") + .setDescription(`${supportbot.NoValidTicket}`) + .setColor(supportbot.WarningColour); + return interaction.reply({ embeds: [Exists] }); + } - if (message.member.roles.cache.has(SupportStaff.id) || message.member.roles.cache.has(Admins.id)) { - if (!message.channel.name.startsWith( `${supportbot.TicketChannel}-` )) { - const Exists = new Discord.MessageEmbed() - .setTitle("No Ticket Found!") - .setDescription(`${supportbot.NoValidTicket}`) - .setColor(supportbot.WarningColour); - message.channel.send({ embeds: [Exists] }); - - return; - } - - let uMember = message.mentions.users.first(); - const UserNotExist = new Discord.MessageEmbed() - .setTitle("User Not Found!") - .setDescription(`${supportbot.UserNotFound}\n\nTry Again:\`${supportbot.Prefix}${cmdconfig.TicketRemove} \``) - .setColor(supportbot.ErrorColour) - - if (!uMember) return message.channel.send({ embeds: [UserNotExist] }); - - message.channel.permissionOverwrites.edit(uMember, { - VIEW_CHANNEL: false, - READ_MESSAGE_HISTORY: false, - SEND_MESSAGES: false, - }); - - const Complete = new Discord.MessageEmbed() - .setTitle("User Removed!") - .setDescription(supportbot.RemovedUser.replace(/%user%/g, uMember.id)) - .setTimestamp() - .setColor(supportbot.EmbedColour) - message.channel.send({ embeds: [Complete] }); - } else { - - return message.channel.send({ embeds: [NoPerms] }); + let uMember = interaction.options.getUser("user"); + const UserNotExist = new Discord.MessageEmbed() + .setTitle("User Not Found!") + .setDescription( + `${supportbot.UserNotFound}\n\nTry Again:\`${supportbot.Prefix}${cmdconfig.TicketRemove} \`` + ) + .setColor(supportbot.ErrorColour); - } + if (!uMember) return interaction.reply({ embeds: [UserNotExist] }); + interaction.channel.permissionOverwrites.edit(uMember, { + VIEW_CHANNEL: false, + READ_MESSAGE_HISTORY: false, + SEND_MESSAGES: false, + }); + + const Complete = new Discord.MessageEmbed() + .setTitle("User Removed!") + .setDescription(supportbot.RemovedUser.replace(/%user%/g, uMember.id)) + .setTimestamp() + .setColor(supportbot.EmbedColour); + interaction.reply({ embeds: [Complete] }); + } else { + return interaction.reply({ embeds: [NoPerms] }); } - -}); \ No newline at end of file + }, +}); diff --git a/Commands/closeticket.js b/Commands/closeticket.js index 7a50c70..c9ed693 100644 --- a/Commands/closeticket.js +++ b/Commands/closeticket.js @@ -4,171 +4,224 @@ const fs = require("fs"); const Discord = require("discord.js"); -const yaml = require('js-yaml'); -const supportbot = yaml.load(fs.readFileSync('./Data/supportbot.yml', 'utf8')); -const cmdconfig = yaml.load(fs.readFileSync('./Data/commands.yml', 'utf8')); +const yaml = require("js-yaml"); +const supportbot = yaml.load(fs.readFileSync("./Data/supportbot.yml", "utf8")); +const cmdconfig = yaml.load(fs.readFileSync("./Data/commands.yml", "utf8")); const Command = require("../Structures/Command.js"); -const TicketNumberID = require('../Structures/TicketID.js'); +const TicketNumberID = require("../Structures/TicketID.js"); async function asyncForEach(array, callback) { - for (let index = 0; index < array.length; index++) { - await callback(array[index], index, array); - } + for (let index = 0; index < array.length; index++) { + await callback(array[index], index, array); } +} module.exports = new Command({ - name: cmdconfig.CloseTicket, - description: cmdconfig.CloseTicketDesc, - type: "BOTH", - slashCommandOptions: [], - permission: "SEND_MESSAGES", + name: cmdconfig.CloseTicket, + description: cmdconfig.CloseTicketDesc, + slashCommandOptions: [ + { + name: "reason", + description: "Ticket Close Reason", + type: "STRING", + }, + ], + permission: "SEND_MESSAGES", - async run(message, args, client) { - - if (!message.channel.name.startsWith( `${supportbot.TicketChannel}-` )) { - const Exists = new Discord.MessageEmbed() - .setTitle("No Ticket Found!") - .setDescription(`${supportbot.NoValidTicket}`) - .setColor(supportbot.WarningColour); - message.channel.send({ embed: Exists }); + async run(interaction) { + if (!interaction.channel.name.startsWith(`${supportbot.TicketChannel}-`)) { + const Exists = new Discord.MessageEmbed() + .setTitle("No Ticket Found!") + .setDescription(`${supportbot.NoValidTicket}`) + .setColor(supportbot.WarningColour); + return interaction.reply({ embed: Exists }); + } - return; + if (supportbot.CloseConfirmation) { + const CloseTicketRequest = new Discord.MessageEmbed() + .setTitle(`**${supportbot.ClosingTicket}**`) + .setDescription( + `Please confirm by repeating the following word.. \`${supportbot.ClosingConfirmation_Word}\` ` + ) + .setColor(supportbot.EmbedColour); - } + interaction + .reply(CloseTicketRequest) + .then((m) => { + interaction.channel + .awaitMessages( + (response) => + response.content.toLowerCase() === + supportbot.ClosingConfirmation_Word, + { + max: 1, + time: 20000, + errors: ["time"], + } + ) + .then((collected) => { + let logChannel = + interaction.guild.channels.cache.find( + (channel) => channel.name === supportbot.TranscriptLog + ) || + interaction.guild.channels.cache.find( + (channel) => channel.id === supportbot.TranscriptLog + ); + let user = interaction.user; + let reason = + interaction.options.getString("reason") || + "No Reason Provided."; - if (supportbot.CloseConfirmation) { - const CloseTicketRequest = new Discord.MessageEmbed() - .setTitle(`**${supportbot.ClosingTicket}**`) - .setDescription(`Please confirm by repeating the following word.. \`${supportbot.ClosingConfirmation_Word}\` `) - .setColor(supportbot.EmbedColour); + let name = interaction.channel.name; + let ticketChannel = interaction.channel; - message.channel.send(CloseTicketRequest).then(m => { - message.channel.awaitMessages( response => response.content.toLowerCase() === supportbot.ClosingConfirmation_Word, { - max: 1, - time: 20000, - errors: [ 'time' ], + interaction + .reply(`**${supportbot.ClosingTicket}**`) - - }).then( collected => { - let logChannel = message.guild.channels.cache.find(channel => channel.name === supportbot.TranscriptLog) || message.guild.channels.cache.find(channel => channel.id === supportbot.TranscriptLog) - let user = message.author; - let reason = args.join(" ") || "No Reason Provided."; + .then(() => { + const logEmbed = new Discord.MessageEmbed() + .setTitle(supportbot.TranscriptTitle) + .setColor(supportbot.EmbedColour) + .setFooter(supportbot.EmbedFooter) + .addField("Closed By", interaction.user.tag) + .addField("Reason", reason); - let name = message.channel.name; - let ticketChannel = message.channel; + interaction.channel.interactions + .fetch({ limit: 100 }) + .then((msgs) => { + let html = ""; - message.channel.send(`**${supportbot.ClosingTicket}**`) + msgs = msgs.sort( + (a, b) => a.createdTimestamp - b.createdTimestamp + ); + html += `Server Name: ${interaction.guild.name}
`; + html += `Ticket: ${ticketChannel.name}
`; + html += `Message: ${msgs.size} Messages


`; - .then(() => { - const logEmbed = new Discord.MessageEmbed() - .setTitle(supportbot.TranscriptTitle) - .setColor(supportbot.EmbedColour) - .setFooter(supportbot.EmbedFooter) - .addField("Closed By", message.author.tag) - .addField("Reason", reason); + msgs.forEach((msg) => { + if (msg.content) { + html += `User: ${msg.author.tag}
`; + html += `Message: ${msg.content}
`; + html += `-----

`; + } + }); - message.channel.messages.fetch({ limit: 100 }).then( msgs => { - let html = ''; + logChannel.send({ embeds: [logEmbed] }).catch((err) => { + interaction.reply(err); + }); - msgs = msgs.sort( ( a, b ) => a.createdTimestamp - b.createdTimestamp ); - html += `Server Name: ${message.guild.name}
`; - html += `Ticket: ${ticketChannel.name}
`; - html += `Message: ${msgs.size} Messages


`; + let file = new Discord.MessageAttachment( + Buffer.from(html), + `${name}.html` + ); + logChannel + .send({ embeds: [logEmbed], files: [file] }) + .catch((err) => { + interaction.reply(err); + }); - msgs.forEach( msg => { - if ( msg.content ) { - html += `User: ${msg.author.tag}
`; - html += `Message: ${msg.content}
`; - html += `-----

`; - } - }); - - logChannel.send({embeds: [logEmbed]}).catch(err => { - message.reply(err) - }) - - - let file = new Discord.MessageAttachment( Buffer.from( html ), `${name}.html` ) - logChannel.send({embeds: [logEmbed], files: [file]}).catch(err => { - message.reply(err) - }) - - message.channel.delete().catch(error => { - if (error.code !== Discord.Constants.APIErrors.UNKNOWN_CHANNEL) { - console.error('Failed to delete the message:', error); - } - }); - - - }) - }) - - }) - - }).catch( () => { - interaction.m.edit({content: 'The request to close the ticket has timed out.'}).then(m2 => setTimeout(() => channel.delete(3000)) ); - }); - - } - - if (!supportbot.CloseConfirmation) { - - let logChannel = message.guild.channels.cache.find(channel => channel.name === supportbot.TranscriptLog) || message.guild.channels.cache.find(channel => channel.id === supportbot.TranscriptLog) - let user = message.author; - let reason = args.join(" ") || "No Reason Provided."; - - let name = message.channel.name; - let ticketChannel = message.channel; - - message.channel.send(`**${supportbot.ClosingTicket}**`) - - .then(() => { - const logEmbed = new Discord.MessageEmbed() - .setTitle(supportbot.TranscriptTitle) - .setColor(supportbot.EmbedColour) - .setFooter(supportbot.EmbedFooter) - .addField("Closed By", message.author.tag) - .addField("Reason", reason); - - message.channel.messages.fetch({ limit: 100 }).then( msgs => { - let html = ''; - - msgs = msgs.sort( ( a, b ) => a.createdTimestamp - b.createdTimestamp ); - html += `Server Name: ${message.guild.name}
`; - html += `Ticket: ${ticketChannel.name}
`; - html += `Message: ${msgs.size} Messages


`; - - msgs.forEach( msg => { - if ( msg.content ) { - html += `User: ${msg.author.tag}
`; - html += `Message: ${msg.content}
`; - html += `-----

`; - } - }); - - logChannel.send({embeds: [logEmbed]}).catch(err => { - message.reply(err) - }) - - let file = new Discord.MessageAttachment( Buffer.from( html ), `${name}.html` ) - logChannel.send({embeds: [logEmbed], files: [file]}).catch(err => { - message.reply(err) - }) - - message.channel.delete().catch(error => { - if (error.code !== Discord.Constants.APIErrors.UNKNOWN_CHANNEL) { - console.error('Failed to delete the message:', error); - } - }); - - }) - - }).catch( () => { - interaction.m.edit({content: 'The request to close the ticket has timed out.'}).then(m2 => setTimeout(() => channel.delete(3000)) ); + interaction.channel.delete().catch((error) => { + if ( + error.code !== + Discord.Constants.APIErrors.UNKNOWN_CHANNEL + ) { + console.error( + "Failed to delete the interaction:", + error + ); + } + }); }); + }); + }); + }) + .catch(() => { + interaction + .followUp({ + content: "The request to close the ticket has timed out.", + }) + .then((m2) => setTimeout(() => interaction.channel.delete(3000))); + }); + } - } + if (!supportbot.CloseConfirmation) { + let logChannel = + interaction.guild.channels.cache.find( + (channel) => channel.name === supportbot.TranscriptLog + ) || + interaction.guild.channels.cache.find( + (channel) => channel.id === supportbot.TranscriptLog + ); + let user = interaction.user; + let reason = + (await interaction.options.getString("reason")) || + "No Reason Provided."; - } + let name = interaction.channel.name; + let ticketChannel = interaction.channel; + + interaction + .reply(`**${supportbot.ClosingTicket}**`) + + .then(() => { + const logEmbed = new Discord.MessageEmbed() + .setTitle(supportbot.TranscriptTitle) + .setColor(supportbot.EmbedColour) + .setFooter(supportbot.EmbedFooter) + .addField("Closed By", interaction.user.tag) + .addField("Reason", reason); + + interaction.channel.interactions + .fetch({ limit: 100 }) + .then((msgs) => { + let html = ""; + + msgs = msgs.sort( + (a, b) => a.createdTimestamp - b.createdTimestamp + ); + html += `Server Name: ${interaction.guild.name}
`; + html += `Ticket: ${ticketChannel.name}
`; + html += `Message: ${msgs.size} Messages


`; + + msgs.forEach((msg) => { + if (msg.content) { + html += `User: ${msg.author.tag}
`; + html += `Message: ${msg.content}
`; + html += `-----

`; + } + }); + + logChannel.send({ embeds: [logEmbed] }).catch((err) => { + interaction.reply(err); + }); + + let file = new Discord.MessageAttachment( + Buffer.from(html), + `${name}.html` + ); + logChannel + .send({ embeds: [logEmbed], files: [file] }) + .catch((err) => { + interaction.reply(err); + }); + + interaction.channel.delete().catch((error) => { + if ( + error.code !== Discord.Constants.APIErrors.UNKNOWN_CHANNEL + ) { + console.error("Failed to delete the interaction:", error); + } + }); + }); + }) + .catch(() => { + interaction + .followUp({ + content: "The request to close the ticket has timed out.", + }) + .then((m2) => setTimeout(() => interaction.channel.delete(3000))); + }); + } + }, }); diff --git a/Commands/help.js b/Commands/help.js index 5597910..3bc320a 100644 --- a/Commands/help.js +++ b/Commands/help.js @@ -4,83 +4,102 @@ const fs = require("fs"); const Discord = require("discord.js"); -const yaml = require('js-yaml'); -const supportbot = yaml.load(fs.readFileSync('./Data/supportbot.yml', 'utf8')); -const cmdconfig = yaml.load(fs.readFileSync('./Data/commands.yml', 'utf8')); +const yaml = require("js-yaml"); +const supportbot = yaml.load(fs.readFileSync("./Data/supportbot.yml", "utf8")); +const cmdconfig = yaml.load(fs.readFileSync("./Data/commands.yml", "utf8")); const Command = require("../Structures/Command.js"); -const TicketNumberID = require('../Structures/TicketID.js'); +const TicketNumberID = require("../Structures/TicketID.js"); async function asyncForEach(array, callback) { - for (let index = 0; index < array.length; index++) { - await callback(array[index], index, array); - } + for (let index = 0; index < array.length; index++) { + await callback(array[index], index, array); } +} module.exports = new Command({ - name: cmdconfig.HelpCommand, - description: cmdconfig.HelpCommandDesc, - type: "BOTH", - slashCommandOptions: [], - permission: "SEND_MESSAGES", + name: cmdconfig.HelpCommand, + description: cmdconfig.HelpCommandDesc, + slashCommandOptions: [], + permission: "SEND_MESSAGES", - async run(message, args, client) { + async run(interaction) { + let SupportStaff = + interaction.guild.roles.cache.find( + (adminRole) => adminRole.name === supportbot.Staff + ) || + interaction.guild.roles.cache.find( + (staffRole) => staffRole.id === supportbot.Staff + ); + let AdminStaff = + interaction.guild.roles.cache.find( + (adminRole) => adminRole.name === supportbot.Admin + ) || + interaction.guild.roles.cache.find( + (adminRole) => adminRole.id === supportbot.Admin + ); - let SupportStaff = message.guild.roles.cache.find(adminRole => adminRole.name === supportbot.Staff) || message.guild.roles.cache.find(staffRole => staffRole.id === supportbot.Staff); - let AdminStaff = message.guild.roles.cache.find(adminRole => adminRole.name === supportbot.Admin) || message.guild.roles.cache.find(adminRole => adminRole.id === supportbot.Admin); - - if (supportbot.HelpMenu) { - let botCommands = ""; - botCommands += `**${supportbot.Prefix}${cmdconfig.HelpCommand}** ${cmdconfig.HelpCommandDesc}\n`; - botCommands += `**${supportbot.Prefix}${cmdconfig.InfoCommand}** ${cmdconfig.InfoCommandDesc}\n`; - botCommands += `**${supportbot.Prefix}${cmdconfig.PingCommand}** ${cmdconfig.PingCommandDesc}\n` - - let ticketCommands = ""; - ticketCommands += `**${supportbot.Prefix}${cmdconfig.OpenTicket}** ${cmdconfig.OpenTicketDesc}\n`; - ticketCommands += `**${supportbot.Prefix}${cmdconfig.CloseTicket}** ${cmdconfig.CloseTicketDesc}\n` + if (supportbot.HelpMenu) { + let botCommands = ""; + botCommands += `**${supportbot.Prefix}${cmdconfig.HelpCommand}** ${cmdconfig.HelpCommandDesc}\n`; + botCommands += `**${supportbot.Prefix}${cmdconfig.InfoCommand}** ${cmdconfig.InfoCommandDesc}\n`; + botCommands += `**${supportbot.Prefix}${cmdconfig.PingCommand}** ${cmdconfig.PingCommandDesc}\n`; - let staffCommands = ""; - staffCommands += `**${supportbot.Prefix}${cmdconfig.TicketAdd}** ${cmdconfig.TicketAddDesc}\n` - staffCommands += `**${supportbot.Prefix}${cmdconfig.TicketRemove}** ${cmdconfig.TicketRemoveDesc}\n` - - const HelpEmbed1 = new Discord.MessageEmbed() - .setTitle(supportbot.Name) - .setThumbnail(message.author.displayAvatarURL()) - - .addFields( - { name: '🖥️ General Commands\n', value: `${botCommands}\n`, inline: false }, - { name: '🎫 Support Commands\n', value: `${ticketCommands}\n`, inline: false }, - ) - - .setColor(supportbot.EmbedColour) - .setFooter(supportbot.EmbedFooter, message.author.displayAvatarURL()); - - if (message.member.roles.cache.has(SupportStaff.id)) { - HelpEmbed1.addFields( - { name: '🔐 Staff Commands\n', value: `${staffCommands}\n`, inline: false }, - ) - } else { - if ((message.member.roles.cache.has(AdminStaff.id))) { - HelpEmbed1.addFields( - { name: '🔐 Staff Commands\n', value: `${staffCommands}\n`, inline: false }, - ) - } - } - - if (supportbot.SendHelpPage === "dm") { - message.author.send({ - embeds: [HelpEmbed1] - }); - } - - if (supportbot.SendHelpPage === "channel") { - message.channel.send({ - embeds: [HelpEmbed1] - }); - } - - - } - + let ticketCommands = ""; + ticketCommands += `**${supportbot.Prefix}${cmdconfig.OpenTicket}** ${cmdconfig.OpenTicketDesc}\n`; + ticketCommands += `**${supportbot.Prefix}${cmdconfig.CloseTicket}** ${cmdconfig.CloseTicketDesc}\n`; + + let staffCommands = ""; + staffCommands += `**${supportbot.Prefix}${cmdconfig.TicketAdd}** ${cmdconfig.TicketAddDesc}\n`; + staffCommands += `**${supportbot.Prefix}${cmdconfig.TicketRemove}** ${cmdconfig.TicketRemoveDesc}\n`; + + const HelpEmbed1 = new Discord.MessageEmbed() + .setTitle(supportbot.Name + " Commands") + .setThumbnail(interaction.user.displayAvatarURL()) + + .addFields( + { + name: "🖥️ General Commands\n", + value: `${botCommands}\n`, + inline: false, + }, + { + name: "🎫 Support Commands\n", + value: `${ticketCommands}\n`, + inline: false, + } + ) + + .setColor(supportbot.EmbedColour) + .setFooter(supportbot.EmbedFooter, interaction.user.displayAvatarURL()); + + if (interaction.member.roles.cache.has(SupportStaff.id)) { + HelpEmbed1.addFields({ + name: "🔐 Staff Commands\n", + value: `${staffCommands}\n`, + inline: false, + }); + } else { + if (interaction.member.roles.cache.has(AdminStaff.id)) { + HelpEmbed1.addFields({ + name: "🔐 Staff Commands\n", + value: `${staffCommands}\n`, + inline: false, + }); } + } + + if (supportbot.SendHelpPage === "dm") { + interaction.user.reply({ + embeds: [HelpEmbed1], + }); + } + + if (supportbot.SendHelpPage === "channel") { + interaction.reply({ + embeds: [HelpEmbed1], + }); + } + } + }, }); diff --git a/Commands/info.js b/Commands/info.js index de0b959..289ce07 100644 --- a/Commands/info.js +++ b/Commands/info.js @@ -4,39 +4,35 @@ const fs = require("fs"); const Discord = require("discord.js"); -const yaml = require('js-yaml'); -const supportbot = yaml.load(fs.readFileSync('./Data/supportbot.yml', 'utf8')); -const cmdconfig = yaml.load(fs.readFileSync('./Data/commands.yml', 'utf8')); +const yaml = require("js-yaml"); +const supportbot = yaml.load(fs.readFileSync("./Data/supportbot.yml", "utf8")); +const cmdconfig = yaml.load(fs.readFileSync("./Data/commands.yml", "utf8")); const Command = require("../Structures/Command.js"); module.exports = new Command({ - name: cmdconfig.InfoCommand, - description: cmdconfig.InfoCommandDesc, - type: "BOTH", - slashCommandOptions: [], - permission: "SEND_MESSAGES", + name: cmdconfig.InfoCommand, + description: cmdconfig.InfoCommandDesc, + slashCommandOptions: [], + permission: "SEND_MESSAGES", - async run(message, args, client) { + async run(interaction) { + const InfoButton = new Discord.MessageButton() + .setLabel(supportbot.InfoButtonText) + .setURL(supportbot.InfoURL) + .setStyle("LINK"); - const InfoButton = new Discord.MessageButton() - .setLabel(supportbot.InfoButtonText) - .setURL(supportbot.InfoURL) - .setStyle('LINK') + const inforow = new Discord.MessageActionRow().addComponents(InfoButton); - const inforow = new Discord.MessageActionRow() - .addComponents(InfoButton) + const InfoEmbed = new Discord.MessageEmbed() + .setURL(supportbot.InfoURL) + .setTitle(supportbot.InfoTitle) + .setDescription(supportbot.AboutMe) + .setColor(supportbot.InfoColour); - const InfoEmbed = new Discord.MessageEmbed() - .setURL(supportbot.InfoURL) - .setTitle(supportbot.InfoTitle) - .setDescription(supportbot.AboutMe) - .setColor(supportbot.InfoColour) - - - message.channel.send({ - embeds: [InfoEmbed], components: [inforow] - }) - - } -}); \ No newline at end of file + interaction.reply({ + embeds: [InfoEmbed], + components: [inforow], + }); + }, +}); diff --git a/commands/ping.js b/commands/ping.js index f4a831e..799b1f4 100644 --- a/commands/ping.js +++ b/commands/ping.js @@ -4,27 +4,27 @@ const fs = require("fs"); const Discord = require("discord.js"); -const yaml = require('js-yaml'); -const supportbot = yaml.load(fs.readFileSync('./Data/supportbot.yml', 'utf8')); -const cmdconfig = yaml.load(fs.readFileSync('./Data/commands.yml', 'utf8')); +const yaml = require("js-yaml"); +const supportbot = yaml.load(fs.readFileSync("./Data/supportbot.yml", "utf8")); +const cmdconfig = yaml.load(fs.readFileSync("./Data/commands.yml", "utf8")); const Command = require("../Structures/Command.js"); module.exports = new Command({ - name: cmdconfig.PingCommand, - description: cmdconfig.PingCommandDesc, - type: "BOTH", - slashCommandOptions: [], - permission: "SEND_MESSAGES", + name: cmdconfig.PingCommand, + description: cmdconfig.PingCommandDesc, + slashCommandOptions: [], + permission: "SEND_MESSAGES", - async run(message, args, client) { + async run(interaction) { + const PingEmbed = new Discord.MessageEmbed() + .setDescription( + `:ping_pong: **Ping:** \`${interaction.client.ws.ping} ms\`` + ) + .setColor(supportbot.EmbedColour); - const PingEmbed = new Discord.MessageEmbed() - .setDescription(`:ping_pong: **Ping:** \`${client.ws.ping} ms\``) - .setColor(supportbot.EmbedColour) - - message.channel.send({ - embeds: [PingEmbed] - }); - } -}); \ No newline at end of file + interaction.reply({ + embeds: [PingEmbed], + }); + }, +}); diff --git a/commands/ticket.js b/commands/ticket.js index b6ef2ac..f1a65d8 100644 --- a/commands/ticket.js +++ b/commands/ticket.js @@ -4,242 +4,358 @@ const fs = require("fs"); const Discord = require("discord.js"); -const yaml = require('js-yaml'); -const supportbot = yaml.load(fs.readFileSync('./Data/supportbot.yml', 'utf8')); -const cmdconfig = yaml.load(fs.readFileSync('./Data/commands.yml', 'utf8')); +const yaml = require("js-yaml"); +const supportbot = yaml.load(fs.readFileSync("./Data/supportbot.yml", "utf8")); +const cmdconfig = yaml.load(fs.readFileSync("./Data/commands.yml", "utf8")); const Command = require("../Structures/Command.js"); -const TicketNumberID = require('../Structures/TicketID.js'); +const TicketNumberID = require("../Structures/TicketID.js"); async function asyncForEach(array, callback) { - for (let index = 0; index < array.length; index++) { - await callback(array[index], index, array); - } + for (let index = 0; index < array.length; index++) { + await callback(array[index], index, array); } +} module.exports = new Command({ - name: cmdconfig.OpenTicket, - description: cmdconfig.OpenTicketDesc, - type: "BOTH", - slashCommandOptions: [], - permission: "SEND_MESSAGES", + name: cmdconfig.OpenTicket, + description: cmdconfig.OpenTicketDesc, + slashCommandOptions: [ + { + name: "reason", + description: "Ticket Reason", + type: "STRING", + }, + ], + permission: "SEND_MESSAGES", - async run(message, args, client) { - - let reactionUser = message.guild.members.cache.get(message.author.id) - - if (reactionUser.roles.cache.find(role => role.name === supportbot.TicketBlackListRole) || reactionUser.roles.cache.find(role => role.id === supportbot.TicketBlackListRole)) { - return message.channel.send({content:`<@${message.author.id}> ${supportbot.TicketBlackListMessage}`}).then(msg => { - setTimeout(() => msg.delete(), 3500) - }) - } - - // Ticket ID - let ticketNumberID = TicketNumberID.pad(message.guild.id); - - // Ticket Subject - const TicketSubject = args || supportbot.NoTicketSubject; - - const TicketExists = new Discord.MessageEmbed() - .setTitle("Ticket Exists!") - .setDescription(`${supportbot.TicketExists}`) - .setColor(supportbot.WarningColour) - - if (message.guild.channels.cache.find(ticketChannel => ticketChannel.name === `${supportbot.TicketChannel}-${ticketNumberID}`)) { - return message.channel.send({ embeds: [TicketExists] }); + async run(interaction) { + let reactionUser = interaction.guild.members.cache.get(interaction.user.id); + + if ( + reactionUser.roles.cache.find( + (role) => role.name === supportbot.TicketBlackListRole + ) || + reactionUser.roles.cache.find( + (role) => role.id === supportbot.TicketBlackListRole + ) + ) { + return interaction + .reply({ + content: `<@${interaction.user.id}> ${supportbot.TicketBlackListMessage}`, + }) + .then((msg) => { + setTimeout(() => msg.delete(), 3500); + }); + } + + // Ticket ID + let ticketNumberID = TicketNumberID.pad(interaction.guild.id); + + // Ticket Subject + const TicketSubject = + interaction.options?.getString("reason") || supportbot.NoTicketSubject; + + const TicketExists = new Discord.MessageEmbed() + .setTitle("Ticket Exists!") + .setDescription(`${supportbot.TicketExists}`) + .setColor(supportbot.WarningColour); + + if ( + interaction.guild.channels.cache.find( + (ticketChannel) => + ticketChannel.name === `${supportbot.TicketChannel}-${ticketNumberID}` + ) + ) { + return interaction.reply({ embeds: [TicketExists] }); + } + const Staff = + interaction.guild.roles.cache.find( + (SupportTeam) => SupportTeam.name === supportbot.Staff + ) || + interaction.guild.roles.cache.find( + (SupportTeam) => SupportTeam.id === supportbot.Staff + ); + const Admins = + interaction.guild.roles.cache.find( + (AdminUser) => AdminUser.name === supportbot.Admin + ) || + interaction.guild.roles.cache.find( + (AdminUser) => AdminUser.id === supportbot.Admin + ); + const DeptRole1 = + interaction.guild.roles.cache.find( + (DepartmentRole) => + DepartmentRole.name === `${supportbot.DepartmentRole_1}` + ) || + interaction.guild.roles.cache.find( + (DepartmentRole) => + DepartmentRole.id === `${supportbot.DepartmentRole_1}` + ); + const DeptRole2 = + interaction.guild.roles.cache.find( + (DepartmentRole) => + DepartmentRole.name === `${supportbot.DepartmentRole_2}` + ) || + interaction.guild.roles.cache.find( + (DepartmentRole) => + DepartmentRole.id === `${supportbot.DepartmentRole_2}` + ); + const DeptRole3 = + interaction.guild.roles.cache.find( + (DepartmentRole) => + DepartmentRole.name === `${supportbot.DepartmentRole_3}` + ) || + interaction.guild.roles.cache.find( + (DepartmentRole) => + DepartmentRole.id === `${supportbot.DepartmentRole_3}` + ); + const Author = interaction.user; + const Everyone = interaction.guild.id; + const ticketChannel = await interaction.guild.channels.create( + `${supportbot.TicketChannel}-${ticketNumberID}`, + { + type: "GUILD_TEXT", + } + ); + + if ( + interaction.channel.name === supportbot.ReactionChannel || + interaction.channel.id === supportbot.ReactionChannel + ) { + const CreatedTicket = new Discord.MessageEmbed() + .setDescription( + supportbot.TicketCreatedAlert.replace( + /%ticketauthor%/g, + interaction.user.id + ) + .replace(/%ticketid%/g, ticketChannel.id) + .replace(/%ticketusername%/g, interaction.user.username) + ) + .setColor(supportbot.EmbedColour); + interaction.reply({ embeds: [CreatedTicket], ephemeral: true }); + } else { + const CreatedTicket = new Discord.MessageEmbed() + .setDescription( + supportbot.TicketCreatedAlert.replace( + /%ticketauthor%/g, + interaction.user.id + ) + .replace(/%ticketid%/g, ticketChannel.id) + .replace(/%ticketusername%/g, interaction.user.username) + ) + .setColor(supportbot.EmbedColour); + interaction.reply({ embeds: [CreatedTicket], ephemeral: true }); + } + let AllowArr = [Staff, Staff, Admins, Author]; + await asyncForEach(AllowArr, (index) => { + ticketChannel.permissionOverwrites.create(index, { VIEW_CHANNEL: true }); + }); + + let DenyArr = [Everyone]; + await asyncForEach(DenyArr, (index) => { + ticketChannel.permissionOverwrites.create(index, { VIEW_CHANNEL: false }); + }); + + let TicketCategory = + interaction.guild.channels.cache.find( + (category) => category.name === supportbot.TicketCategory + ) || + interaction.guild.channels.cache.find( + (category) => category.id === supportbot.TicketCategory + ); + if (TicketCategory) { + ticketChannel.setParent(TicketCategory.id); + } + + if (supportbot.AllowTicketMentions) { + ticketChannel.send({ content: `${interaction.user}` }); + } + + const TicketMessage = new Discord.MessageEmbed() + .setTitle( + supportbot.Ticket_Title.replace(/%ticketauthor%/g, interaction.user.id) + .replace(/%ticketid%/g, ticketChannel.id) + .replace(/%ticketusername%/g, interaction.user.username) + ) + .setDescription( + supportbot.TicketMessage.replace(/%ticketauthor%/g, interaction.user.id) + .replace(/%ticketid%/g, ticketChannel.id) + .replace(/%ticketusername%/g, interaction.user.username) + ) + .setColor(supportbot.EmbedColour); + + if (supportbot.TicketSubject === "embed") { + if (TicketSubject != "No Reason Provided.") { + TicketMessage.addFields({ name: "Reason", value: TicketSubject }); + } + } + + if (supportbot.TicketSubject === "description") { + if (TicketSubject != "No Reason Provided.") { + ticketChannel.setTopic( + `Reason: ${TicketSubject} - User ID: ${interaction.user.id} - Ticket: ${ticketChannel.name}` + ); + } + } + + if (supportbot.TicketDepartments) { + TicketMessage.addFields({ + name: "Departments", + value: ` **${supportbot.DepartmentTitle_1}**\n **${supportbot.DepartmentTitle_2}**\n **${supportbot.DepartmentTitle_3}**`, + }); + } + const CloseButton = new Discord.MessageButton() + .setCustomId("ticketclose") + .setLabel("Close") + .setStyle(supportbot.TicketCloseColour) + .setEmoji(supportbot.TicketCloseEmoji); + + const LockButton = new Discord.MessageButton() + .setCustomId("ticketlock") + .setLabel("Lock") + .setStyle(supportbot.TicketLockColour) + .setEmoji(supportbot.TicketLockEmoji); + + const row2 = new Discord.MessageActionRow().addComponents( + CloseButton, + LockButton + ); + + if (supportbot.TicketDepartments) { + let DenyArr = [DeptRole1, DeptRole2, DeptRole3]; + await asyncForEach(DenyArr, (index) => { + ticketChannel.permissionOverwrites.create(index, { + VIEW_CHANNEL: false, + }); + }); + const Department1Button = new Discord.MessageButton() + .setCustomId("Department1") + .setLabel(`${supportbot.DepartmentTitle_1}`) + .setStyle(supportbot.TicketDept1Colour) + .setEmoji(supportbot.TicketDept1Emoji); + + const Department2Button = new Discord.MessageButton() + .setCustomId("Department2") + .setLabel(`${supportbot.DepartmentTitle_2}`) + .setStyle(supportbot.TicketDept2Colour) + .setEmoji(supportbot.TicketDept2Emoji); + + const Department3Button = new Discord.MessageButton() + .setCustomId("Department3") + .setLabel(`${supportbot.DepartmentTitle_3}`) + .setStyle(supportbot.TicketDept3Colour) + .setEmoji(supportbot.TicketDept3Emoji); + + const row = new Discord.MessageActionRow().addComponents( + Department1Button, + Department2Button, + Department3Button + ); + + const m = await ticketChannel.send({ + embeds: [TicketMessage], + components: [row], + }); + + const filter = (i) => { + i.deferUpdate(); + return i.user.id === interaction.user.id; + }; + const collector = m.createMessageComponentCollector({ + filter, + max: 1, + componentType: "BUTTON", + time: 60000, + }); + + collector.on("collect", async (i) => { + if (i.customId === "Department1") { + ticketChannel.permissionOverwrites.edit(DeptRole1, { + VIEW_CHANNEL: true, + READ_MESSAGE_HISTORY: true, + SEND_MESSAGES: true, + }); + + if (!supportbot.AllowStaff) { + ticketChannel.permissionOverwrites.edit(Staff, { + VIEW_CHANNEL: false, + READ_MESSAGE_HISTORY: false, + SEND_MESSAGES: false, + }); } - const Staff = message.guild.roles.cache.find(SupportTeam => SupportTeam.name === supportbot.Staff) || message.guild.roles.cache.find(SupportTeam => SupportTeam.id === supportbot.Staff) - const Admins = message.guild.roles.cache.find(AdminUser => AdminUser.name === supportbot.Admin) || message.guild.roles.cache.find(AdminUser => AdminUser.id === supportbot.Admin) - const DeptRole1 = message.guild.roles.cache.find(DepartmentRole => DepartmentRole.name === `${supportbot.DepartmentRole_1}`) || message.guild.roles.cache.find(DepartmentRole => DepartmentRole.id === `${supportbot.DepartmentRole_1}`) - const DeptRole2 = message.guild.roles.cache.find(DepartmentRole => DepartmentRole.name === `${supportbot.DepartmentRole_2}`) || message.guild.roles.cache.find(DepartmentRole => DepartmentRole.id === `${supportbot.DepartmentRole_2}`) - const DeptRole3 = message.guild.roles.cache.find(DepartmentRole => DepartmentRole.name === `${supportbot.DepartmentRole_3}`) || message.guild.roles.cache.find(DepartmentRole => DepartmentRole.id === `${supportbot.DepartmentRole_3}`) - const Author = message.author - const Everyone = message.guild.id - const ticketChannel = await message.guild.channels.create(`${supportbot.TicketChannel}-${ticketNumberID}`, { - type: "GUILD_TEXT", - }) - - if (message.channel.name === supportbot.ReactionChannel || message.channel.id === supportbot.ReactionChannel) { - const CreatedTicket = new Discord.MessageEmbed() - .setDescription(supportbot.TicketCreatedAlert.replace(/%ticketauthor%/g, message.author.id).replace(/%ticketid%/g, ticketChannel.id).replace(/%ticketusername%/g, message.author.username)) - .setColor(supportbot.EmbedColour) - message.channel.send({embeds: [CreatedTicket]}).then(msg => { - setTimeout(() => msg.delete(), 5000) - }) - } else { - const CreatedTicket = new Discord.MessageEmbed() - .setDescription(supportbot.TicketCreatedAlert.replace(/%ticketauthor%/g, message.author.id).replace(/%ticketid%/g, ticketChannel.id).replace(/%ticketusername%/g, message.author.username)) - .setColor(supportbot.EmbedColour) - message.channel.send({embeds: [CreatedTicket]}).then(msg => setTimeout(() => msg.delete(), 5000)); - } - let AllowArr = [Staff, Staff, Admins, Author] - await asyncForEach(AllowArr, (index) => { - ticketChannel.permissionOverwrites.create(index, {VIEW_CHANNEL: true}) - }) - - let DenyArr = [Everyone] - await asyncForEach(DenyArr, (index) => { - ticketChannel.permissionOverwrites.create(index, {VIEW_CHANNEL: false}) - }) - - let TicketCategory = message.guild.channels.cache.find(category => category.name === supportbot.TicketCategory) || message.guild.channels.cache.find(category => category.id === supportbot.TicketCategory) - if(TicketCategory) { - ticketChannel.setParent(TicketCategory.id) - } - + + const Department1 = new Discord.MessageEmbed() + .setDescription( + `> Thank for reaching out to the **${supportbot.DepartmentTitle_1} Department**. Please provide us information regarding your query.` + ) + .setColor(supportbot.EmbedColour); + ticketChannel.send({ embeds: [Department1] }); + if (supportbot.AllowTicketMentions) { - ticketChannel.send({content:`${message.author}`}) + ticketChannel.send({ content: `@here` }); } - - const TicketMessage = new Discord.MessageEmbed() - .setTitle(supportbot.Ticket_Title.replace(/%ticketauthor%/g, message.author.id).replace(/%ticketid%/g, ticketChannel.id).replace(/%ticketusername%/g, message.author.username)) - .setDescription(supportbot.TicketMessage.replace(/%ticketauthor%/g, message.author.id).replace(/%ticketid%/g, ticketChannel.id).replace(/%ticketusername%/g, message.author.username)) - .setColor(supportbot.EmbedColour) - - if (supportbot.TicketSubject === "embed") { - - if (TicketSubject != 'No Reason Provided.') { - TicketMessage.addFields({ name: 'Reason', value: TicketSubject }) - } - - } - - if (supportbot.TicketSubject === "description") { - - if (TicketSubject != 'No Reason Provided.') { - ticketChannel.setTopic(`Reason: ${TicketSubject} - User ID: ${message.author.id} - Ticket: ${ticketChannel.name}`) - } - - } - - if (supportbot.TicketDepartments) { - TicketMessage.addFields({ name: 'Departments', value: ` **${supportbot.DepartmentTitle_1}**\n **${supportbot.DepartmentTitle_2}**\n **${supportbot.DepartmentTitle_3}**` }) - } - const CloseButton = new Discord.MessageButton() - .setCustomId('ticketclose') - .setLabel('Close') - .setStyle(supportbot.TicketCloseColour) - .setEmoji(supportbot.TicketCloseEmoji) - - const LockButton = new Discord.MessageButton() - .setCustomId('ticketlock') - .setLabel('Lock') - .setStyle(supportbot.TicketLockColour) - .setEmoji(supportbot.TicketLockEmoji) - - const row2 = new Discord.MessageActionRow() - .addComponents(CloseButton, LockButton) - - if(supportbot.TicketDepartments) { - - let DenyArr = [DeptRole1, DeptRole2, DeptRole3] - await asyncForEach(DenyArr, (index) => { - ticketChannel.permissionOverwrites.create(index, {VIEW_CHANNEL: false}) - }) - const Department1Button = new Discord.MessageButton() - .setCustomId('Department1') - .setLabel(`${supportbot.DepartmentTitle_1}`) - .setStyle(supportbot.TicketDept1Colour) - .setEmoji(supportbot.TicketDept1Emoji) - - const Department2Button = new Discord.MessageButton() - .setCustomId('Department2') - .setLabel(`${supportbot.DepartmentTitle_2}`) - .setStyle(supportbot.TicketDept2Colour) - .setEmoji(supportbot.TicketDept2Emoji) - - const Department3Button = new Discord.MessageButton() - .setCustomId('Department3') - .setLabel(`${supportbot.DepartmentTitle_3}`) - .setStyle(supportbot.TicketDept3Colour) - .setEmoji(supportbot.TicketDept3Emoji) - - const row = new Discord.MessageActionRow() - .addComponents(Department1Button, Department2Button, Department3Button) - - const m = await ticketChannel.send({embeds: [TicketMessage], components: [row]}) - - const filter = i => { - i.deferUpdate(); - return i.user.id === message.author.id; - }; - const collector = m.createMessageComponentCollector({ filter, max: 1, componentType: 'BUTTON', time: 60000 }); - - collector.on('collect',async (i) => { - - if(i.customId === 'Department1') { - - ticketChannel.permissionOverwrites.edit(DeptRole1, { - VIEW_CHANNEL: true, - READ_MESSAGE_HISTORY: true, - SEND_MESSAGES: true, - }) - - if(!supportbot.AllowStaff) { - ticketChannel.permissionOverwrites.edit(Staff, { VIEW_CHANNEL: false, READ_MESSAGE_HISTORY: false, SEND_MESSAGES: false }) - } - - const Department1 = new Discord.MessageEmbed() - .setDescription(`> Thank for reaching out to the **${supportbot.DepartmentTitle_1} Department**. Please provide us information regarding your query.`) - .setColor(supportbot.EmbedColour) - ticketChannel.send({ embeds: [Department1] }); - - if (supportbot.AllowTicketMentions) { - ticketChannel.send({content: `@here`}) - } - } - i.message.edit({embeds: [TicketMessage], components: [row2]}) - - if(i.customId === 'Department2') { - - ticketChannel.permissionOverwrites.edit(DeptRole2, { - VIEW_CHANNEL: true, - READ_MESSAGE_HISTORY: true, - SEND_MESSAGES: true, - }) - - if(!supportbot.AllowStaff) { - ticketChannel.permissionOverwrites.edit(Staff, { VIEW_CHANNEL: false, READ_MESSAGE_HISTORY: false, SEND_MESSAGES: false }) - } - - - const Department2 = new Discord.MessageEmbed() - .setDescription(`> Thank for reaching out to the **${supportbot.DepartmentTitle_2} Department**. Please provide us information regarding your query.`) - .setColor(supportbot.EmbedColour) - ticketChannel.send({ embeds: [Department2] }); - - if (supportbot.AllowTicketMentions) { - ticketChannel.send({content: `@here`}) - } - - i.message.edit({embeds: [TicketMessage], components: [row2]}) - } - if(i.customId === 'Department3') { - - ticketChannel.permissionOverwrites.edit(DeptRole3, { - VIEW_CHANNEL: true, - READ_MESSAGE_HISTORY: true, - SEND_MESSAGES: true, - }) - - if(!supportbot.AllowStaff) { - ticketChannel.permissionOverwrites.edit(Staff, { VIEW_CHANNEL: false, READ_MESSAGE_HISTORY: false, SEND_MESSAGES: false }) - } - - const Department3 = new Discord.MessageEmbed() - .setDescription(`> Thank for reaching out to the **${supportbot.DepartmentTitle_3} Department**. Please provide us information regarding your query.`) - .setColor(supportbot.EmbedColour) - ticketChannel.send({ embeds: [Department3] }); - - if (supportbot.AllowTicketMentions) { - ticketChannel.send({content: `@here`}) - } - i.message.edit({embeds: [TicketMessage], components: [row2]}) - } - }) - } else { - ticketChannel.send({embeds: [TicketMessage], components: [row2]}) + } + i.message.edit({ embeds: [TicketMessage], components: [row2] }); + + if (i.customId === "Department2") { + ticketChannel.permissionOverwrites.edit(DeptRole2, { + VIEW_CHANNEL: true, + READ_MESSAGE_HISTORY: true, + SEND_MESSAGES: true, + }); + + if (!supportbot.AllowStaff) { + ticketChannel.permissionOverwrites.edit(Staff, { + VIEW_CHANNEL: false, + READ_MESSAGE_HISTORY: false, + SEND_MESSAGES: false, + }); } - } + const Department2 = new Discord.MessageEmbed() + .setDescription( + `> Thank for reaching out to the **${supportbot.DepartmentTitle_2} Department**. Please provide us information regarding your query.` + ) + .setColor(supportbot.EmbedColour); + ticketChannel.send({ embeds: [Department2] }); + + if (supportbot.AllowTicketMentions) { + ticketChannel.send({ content: `@here` }); + } + + i.message.edit({ embeds: [TicketMessage], components: [row2] }); + } + if (i.customId === "Department3") { + ticketChannel.permissionOverwrites.edit(DeptRole3, { + VIEW_CHANNEL: true, + READ_MESSAGE_HISTORY: true, + SEND_MESSAGES: true, + }); + + if (!supportbot.AllowStaff) { + ticketChannel.permissionOverwrites.edit(Staff, { + VIEW_CHANNEL: false, + READ_MESSAGE_HISTORY: false, + SEND_MESSAGES: false, + }); + } + + const Department3 = new Discord.MessageEmbed() + .setDescription( + `> Thank for reaching out to the **${supportbot.DepartmentTitle_3} Department**. Please provide us information regarding your query.` + ) + .setColor(supportbot.EmbedColour); + ticketChannel.send({ embeds: [Department3] }); + + if (supportbot.AllowTicketMentions) { + ticketChannel.send({ content: `@here` }); + } + i.message.edit({ embeds: [TicketMessage], components: [row2] }); + } + }); + } else { + ticketChannel.send({ embeds: [TicketMessage], components: [row2] }); + } + }, });