diff --git a/commands/addUser.js b/commands/addUser.js index 12a591f..7a2a827 100755 --- a/commands/addUser.js +++ b/commands/addUser.js @@ -28,7 +28,7 @@ module.exports = { .setTitle("No Ticket Found!") .setDescription(`${supportbot.NoValidTicket}`) .setColor(supportbot.WarningColour); - message.channel.send({ embed: Exists }); + message.channel.send({ embeds: [Exists] }); return; } @@ -39,7 +39,7 @@ module.exports = { .setDescription(`${supportbot.UserNotFound}\n\nTry Again:\`${supportbot.Prefix}${supportbot.AddUser} \``) .setColor(supportbot.ErrorColour) - if (!rUser) return message.channel.send({ embed: UserNotExist }); + if (!rUser) return message.channel.send({ embeds: [UserNotExist] }); message.channel.updateOverwrite(rUser, { VIEW_CHANNEL: true, @@ -53,10 +53,10 @@ module.exports = { .setDescription(supportbot.AddedUser.replace(/%user%/g, rUser.id)) .setTimestamp() .setColor(supportbot.EmbedColour) - message.channel.send({ embed: Complete }); + message.channel.send({ embeds: [Complete] }); } else { - return message.channel.send({ embed: NoPerms }); + return message.channel.send({ embeds: [NoPerms] }); } diff --git a/commands/announce.js b/commands/announce.js index 8554ec0..94828ae 100755 --- a/commands/announce.js +++ b/commands/announce.js @@ -23,7 +23,7 @@ module.exports = { .setDescription(`${supportbot.InvalidChannel}\n\nChannel Required: \`${supportbot.AnnouncementChannel}`) .setColor(supportbot.ErrorColour); - if(!locateChannel) return message.channel.send({ embed: errornochannel }); + if(!locateChannel) return message.channel.send({ embeds: [errornochannel] }); let Admins = message.guild.roles.cache.find(adminRole => adminRole.name === supportbot.Admin) || message.guild.roles.cache.find(adminRole => adminRole.id === supportbot.Admin) @@ -33,13 +33,13 @@ module.exports = { .setColor(supportbot.WarningColour) if (!message.member.roles.cache.has(Admins.id)) - return message.channel.send({ embed: NoPerms }); + return message.channel.send({ embeds: [NoPerms] }); const embed = new Discord.MessageEmbed() .setDescription(`> **${supportbot.AnnouncementStarter}**`) .setColor(supportbot.EmbedColour) - message.channel.send({ embed: embed }); + message.channel.send({ embeds: [embed] }); let announcement = [] message.channel.awaitMessages(response => response.content.length > 2, { @@ -61,7 +61,7 @@ module.exports = { const AnnouncementComplete = new Discord.MessageEmbed() .setColor(supportbot.SuccessColour) .setDescription(`:white_check_mark: You have successfully created an announcement. <#${locateChannel.id}>`) - message.channel.send({ embed: AnnouncementComplete }) + message.channel.send({ embeds: [AnnouncementComplete] }) }) }); diff --git a/commands/ban.js b/commands/ban.js index de16ffd..0cb81f3 100644 --- a/commands/ban.js +++ b/commands/ban.js @@ -23,7 +23,7 @@ module.exports = { .setColor(supportbot.WarningColour) if (!message.member.roles.cache.has(SupportStaff.id)) - return message.channel.send({ embed: NoPerms }); + return message.channel.send({ embeds: [NoPerms] }); let locateChannel = message.guild.channels.cache.find(ModLogChannel => ModLogChannel.name === supportbot.ModLogChannel) || message.guild.channels.cache.find(ModLogChannel => ModLogChannel.id === supportbot.ModLogChannel) @@ -32,7 +32,7 @@ module.exports = { .setDescription(`${supportbot.InvalidChannel}\n\nChannel Required: \`${supportbot.ModLogChannel}\``) .setColor(supportbot.ErrorColour); - if(!locateChannel) return message.channel.send({ embed: errornochannel }); + if(!locateChannel) return message.channel.send({ embeds: [errornochannel] }); const user = message.mentions.members.first() || message.guild.members.cache.get(args[0]); @@ -41,7 +41,7 @@ module.exports = { .setColor(supportbot.ErrorColour) if (!args[0]) return message.channel.send({ - embed: embed1 + embeds: [embed1] }); const embed2 = new Discord.MessageEmbed() @@ -49,7 +49,7 @@ module.exports = { .setColor(supportbot.EmbedColour) if (!user) return message.channel.send({ - embed: embed2 + embeds: [embed2] }) const embed3 = new Discord.MessageEmbed() @@ -57,7 +57,7 @@ module.exports = { .setColor(supportbot.EmbedColour) if(!user.bannable) return message.channel.send({ - embed: embed3 + embeds: [embed3] }); const embed4 = new Discord.MessageEmbed() @@ -65,7 +65,7 @@ module.exports = { .setColor(supportbot.EmbedColour) if(user.id === message.author.id) return message.channel.send({ - embed: embed4 + embeds: [embed4] }); let reason = args.slice(1).join(" "); @@ -77,7 +77,7 @@ module.exports = { .setColor(supportbot.EmbedColour) user.ban({ days: supportbot.DaysBannedFor, reason: `${reason}` }).catch(err => { - message.channel.send({ embed: embed5 }) + message.channel.send({ embeds: [embed5] }) console.log(err) }) @@ -99,7 +99,7 @@ module.exports = { .setColor(supportbot.BanLogColour) .setTimestamp() - locateChannel.send({ embed: logEmbed }) + locateChannel.send({ embeds: [logEmbed] }) diff --git a/commands/blacklistUser.js b/commands/blacklistUser.js index ba4fda7..ecefa49 100644 --- a/commands/blacklistUser.js +++ b/commands/blacklistUser.js @@ -23,7 +23,7 @@ module.exports = { .setColor(supportbot.WarningColour) if (!message.member.roles.cache.has(SupportStaff.id)) { - return message.channel.send({ embed: NoPerms }); + return message.channel.send({ embeds: [NoPerms] }); } let locateChannel = message.guild.channels.cache.find(ModLogChannel => ModLogChannel.name === supportbot.ModLogChannel) || message.guild.channels.cache.find(ModLogChannel => ModLogChannel.id === supportbot.ModLogChannel) @@ -35,14 +35,14 @@ module.exports = { .setDescription(`${supportbot.InvalidChannel}\n\nChannel Required: \`${supportbot.ModLogChannel}\``) .setColor(supportbot.ErrorColour); - if(!locateChannel) return message.channel.send({ embed: errornochannel }); + if(!locateChannel) return message.channel.send({ embeds: [errornochannel] }); const embed1 = new Discord.MessageEmbed() .setDescription("> :x: Please mention or write an ID\n\n`Try Again!`") .setColor(supportbot.ErrorColour) if (!args[0]) return message.channel.send({ - embed: embed1 + embeds: [embed1] }); const embed2 = new Discord.MessageEmbed() @@ -50,7 +50,7 @@ module.exports = { .setColor(supportbot.EmbedColour) if (!user) return message.channel.send({ - embed: embed2 + embeds: [embed2] }); let role = message.guild.roles.cache.find(role => role.name === supportbot.TicketBlackListRole) || message.guild.roles.cache.find(role => role.id === supportbot.TicketBlackListRole) @@ -61,7 +61,7 @@ module.exports = { if (!role) return message.channel.send({ - embed: embed3 + embeds: [embed3] }); const embed4 = new Discord.MessageEmbed() @@ -70,7 +70,7 @@ module.exports = { if(user.roles.cache.find(role => role.name === supportbot.TicketBlackListRole) || user.roles.cache.find(role => role.id === supportbot.TicketBlackListRole)) { return message.channel.send({ - embed: embed4 + embeds: [embed4] }) }; @@ -81,7 +81,7 @@ module.exports = { .setColor(supportbot.EmbedColour) message.channel.send({ - embed: embed5 + embeds: [embed5] }); const logEmbed = new Discord.MessageEmbed() @@ -93,7 +93,7 @@ module.exports = { .setColor(supportbot.BlacklistColour) .setTimestamp() - locateChannel.send({ embed: logEmbed }); + locateChannel.send({ embeds: [logEmbed] }); } diff --git a/commands/botSay.js b/commands/botSay.js index 8fe0e76..7947417 100644 --- a/commands/botSay.js +++ b/commands/botSay.js @@ -23,13 +23,13 @@ module.exports = { .setColor(supportbot.WarningColour) if (!message.member.roles.cache.has(SupportStaff.id)) - return message.channel.send({ embed: NoPerms }); + return message.channel.send({ embeds: [NoPerms] }); const embed = new Discord.MessageEmbed() .setDescription(`> **What would you like me to say!**`) .setColor(supportbot.EmbedColour) - message.channel.send({ embed: embed }); + message.channel.send({ embeds: [embed] }); let announcement = [] message.channel.awaitMessages(response => response.content.length > 2, { @@ -43,7 +43,7 @@ module.exports = { .setDescription(announcement) .setColor(supportbot.EmbedColour) - message.channel.send({ embed: AnnouncementEmbed }) + message.channel.send({ embeds: [AnnouncementEmbed] }) }) } diff --git a/commands/close.js b/commands/close.js index 873e757..d0775c0 100755 --- a/commands/close.js +++ b/commands/close.js @@ -73,13 +73,22 @@ module.exports = { } }); - logChannel.send(logEmbed).catch(err => { + logChannel.send({embeds: [logEmbed]}).catch(err => { message.reply(err) }) - logChannel.send( new Discord.MessageAttachment( Buffer.from( html ), `${name}.html` ) ); - message.channel.delete(); + 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); + } + }); + }) }) @@ -87,7 +96,7 @@ module.exports = { }) }).catch( () => { - m.edit('The request to close the ticket has timed out.').then( m2 => m2.delete( 3000 ) ); + interaction.m.edit({content: 'The request to close the ticket has timed out.'}).then(m2 => setTimeout(() => channel.delete(3000)) ); }); } @@ -127,21 +136,28 @@ module.exports = { } }); - logChannel.send(logEmbed).catch(err => { + logChannel.send({embeds: [logEmbed]}).catch(err => { message.reply(err) }) - logChannel.send( new Discord.MessageAttachment( Buffer.from( html ), `${name}.html` ) ); + let file = new Discord.MessageAttachment( Buffer.from( html ), `${name}.html` ) + logChannel.send({embeds: [logEmbed], files: [file]}).catch(err => { + message.reply(err) + }) - message.channel.delete(); + message.channel.delete().catch(error => { + if (error.code !== Discord.Constants.APIErrors.UNKNOWN_CHANNEL) { + console.error('Failed to delete the message:', error); + } + }); }) }).catch( () => { - m.edit('The request to close the ticket has timed out.').then( m2 => m2.delete( 3000 ) ); + interaction.m.edit({content: 'The request to close the ticket has timed out.'}).then(m2 => setTimeout(() => channel.delete(3000)) ); }); } } -}; +}; \ No newline at end of file diff --git a/commands/help.js b/commands/help.js index 78a8f58..84e0779 100644 --- a/commands/help.js +++ b/commands/help.js @@ -11,6 +11,7 @@ module.exports = { name: supportbot.HelpCommand, description: supportbot.HelpDesc, + execute(message, args) { if (supportbot.DeleteMessages) message.delete(); @@ -67,13 +68,13 @@ module.exports = { if (supportbot.SendHelpPage === "dm") { message.author.send({ - embed: HelpEmbed1 + embeds: [HelpEmbed1] }); } if (supportbot.SendHelpPage === "channel") { message.channel.send({ - embed: HelpEmbed1 + embeds: [HelpEmbed1] }); } diff --git a/commands/kick.js b/commands/kick.js index 4b8212c..8261a48 100644 --- a/commands/kick.js +++ b/commands/kick.js @@ -23,7 +23,7 @@ module.exports = { .setColor(supportbot.WarningColour) if (!message.member.roles.cache.has(SupportStaff.id)) - return message.channel.send({ embed: NoPerms }); + return message.channel.send({ embeds: [NoPerms] }); let locateChannel = message.guild.channels.cache.find(ModLogChannel => ModLogChannel.name === supportbot.ModLogChannel) || message.guild.channels.cache.find(ModLogChannel => ModLogChannel.id === supportbot.ModLogChannel) @@ -32,7 +32,7 @@ module.exports = { .setDescription(`${supportbot.InvalidChannel}\n\nChannel Required: \`${supportbot.ModLogChannel}\``) .setColor(supportbot.ErrorColour); - if(!locateChannel) return message.channel.send({ embed: errornochannel }); + if(!locateChannel) return message.channel.send({ embeds: [errornochannel] }); const user = message.mentions.members.first() || message.guild.members.cache.get(args[0]); @@ -41,7 +41,7 @@ module.exports = { .setColor(supportbot.ErrorColour) if (!args[0]) return message.channel.send({ - embed: embed1 + embeds: [embed1] }); const embed2 = new Discord.MessageEmbed() @@ -49,7 +49,7 @@ module.exports = { .setColor(supportbot.EmbedColour) if (!user) return message.channel.send({ - embed: embed2 + embeds: [embed2] }) const embed3 = new Discord.MessageEmbed() @@ -57,7 +57,7 @@ module.exports = { .setColor(supportbot.EmbedColour) if(!user.kickable) return message.channel.send({ - embed: embed3 + embeds: [embed3] }); const embed4 = new Discord.MessageEmbed() @@ -65,7 +65,7 @@ module.exports = { .setColor(supportbot.EmbedColour) if(user.id === message.author.id) return message.channel.send({ - embed: embed4 + embeds: [embed4] }); let reason = args.slice(1).join(" "); @@ -77,7 +77,7 @@ module.exports = { .setColor(supportbot.EmbedColour) user.kick({ reason: `${reason}` }).catch(err => { - message.channel.send({ embed: embed5 }) + message.channel.send({ embeds: [embed5] }) console.log(err) }) @@ -87,7 +87,7 @@ module.exports = { .setColor(supportbot.SuccessColour) message.channel.send({ - embed: successEmbed + embeds: [successEmbed] }) const logEmbed = new Discord.MessageEmbed() @@ -100,7 +100,7 @@ module.exports = { .setColor(supportbot.KickLogColour) .setTimestamp() - locateChannel.send({ embed: logEmbed }) + locateChannel.send({ embeds: [logEmbed] }) diff --git a/commands/links.js b/commands/links.js index 9c922fd..a312b2c 100755 --- a/commands/links.js +++ b/commands/links.js @@ -28,7 +28,7 @@ module.exports = { LinksEmbed.addField(supportbot.LinksTitle, links) - message.channel.send({ embed: LinksEmbed }); + message.channel.send({ embeds: [LinksEmbed] }); } }; diff --git a/commands/ping.js b/commands/ping.js index 02897f5..8e05a88 100755 --- a/commands/ping.js +++ b/commands/ping.js @@ -20,6 +20,6 @@ module.exports = { .setDescription(`🏓 **Pong!** \`${Date.now() - message.createdTimestamp}ms\``) .setColor(supportbot.EmbedColour) - message.channel.send({ embed: PingCommandEmbed }); + message.channel.send({ embeds: [PingCommandEmbed] }); } }; diff --git a/commands/purge.js b/commands/purge.js index 102d1b7..af2aa1c 100644 --- a/commands/purge.js +++ b/commands/purge.js @@ -23,7 +23,7 @@ module.exports = { .setColor(supportbot.WarningColour) if (!message.member.roles.cache.has(SupportStaff.id)) - return message.channel.send({ embed: NoPerms }); + return message.channel.send({ embeds: [NoPerms] }); let locateChannel = message.guild.channels.cache.find(ModLogChannel => ModLogChannel.name === supportbot.ModLogChannel) || message.guild.channels.cache.find(ModLogChannel => ModLogChannel.id === supportbot.ModLogChannel) @@ -32,14 +32,14 @@ module.exports = { .setDescription(`${supportbot.InvalidChannel}\n\nChannel Required: \`${supportbot.ModLogChannel}\``) .setColor(supportbot.ErrorColour); - if(!locateChannel) return message.channel.send({ embed: errornochannel }); + if(!locateChannel) return message.channel.send({ embeds: [errornochannel] }); const embed1 = new Discord.MessageEmbed() .setDescription(`> :thinking: **Hmm!** Please enter a valid number of message to purge!\n\n\`${supportbot.Prefix}${supportbot.PurgeMessage} \` `) .setColor(supportbot.WarningColour) if (!args[0]) return message.channel.send({ - embed: embed1 + embeds: [embed1] }); const messagePrune = parseInt(args[0]) @@ -49,7 +49,7 @@ module.exports = { .setColor(supportbot.ErrorColour) if (isNaN(messagePrune)) return message.reply({ - embed: embed2 + embeds: [embed2] }) message.channel.bulkDelete(messagePrune).then(() => { @@ -58,7 +58,7 @@ module.exports = { .setDescription(`> :recycle: \`${args[0]} messages\` **have been purged!** `) .setColor(supportbot.ErrorColour) message.channel.send({ - embed: embed3 + embeds: [embed3] }) }) @@ -71,7 +71,7 @@ module.exports = { .setColor(supportbot.PruneColour) .setTimestamp() - locateChannel.send({ embed: logEmbed }) + locateChannel.send({ embeds: [logEmbed] }) diff --git a/commands/removeUser.js b/commands/removeUser.js index 8711236..88a5432 100755 --- a/commands/removeUser.js +++ b/commands/removeUser.js @@ -28,7 +28,7 @@ module.exports = { .setTitle("No Ticket Found!") .setDescription(`${supportbot.NoValidTicket}`) .setColor(supportbot.WarningColour); - message.channel.send({ embed: Exists }); + message.channel.send({ embeds: [Exists] }); return; } @@ -39,7 +39,7 @@ module.exports = { .setDescription(`${supportbot.UserNotFound}\n\nTry Again:\`${supportbot.Prefix}${supportbot.RemoveUser} \``) .setColor(supportbot.ErrorColour) - if (!rUser) return message.channel.send({ embed: UserNotExist }); + if (!rUser) return message.channel.send({ embeds: [UserNotExist] }); message.channel.updateOverwrite(rUser, { VIEW_CHANNEL: false, @@ -53,9 +53,9 @@ module.exports = { .setDescription(supportbot.RemovedUser.replace(/%user%/g, rUser.id)) .setTimestamp() .setColor(supportbot.EmbedColour) - message.channel.send({ embed: Complete }); + message.channel.send({ embeds: [Complete] }); } else { - return message.channel.send({ embed: NoPerms }); + return message.channel.send({ embeds: [NoPerms] }); } } diff --git a/commands/suggest.js b/commands/suggest.js index 473f49a..e039507 100755 --- a/commands/suggest.js +++ b/commands/suggest.js @@ -21,12 +21,12 @@ module.exports = { .setDescription(`${supportbot.InvalidChannel}\n\nChannel Required: \`${supportbot.SuggestionChannel}\``) .setColor(supportbot.ErrorColour); - if(!locateChannel) return message.channel.send({ embed: errornochannel }); + if(!locateChannel) return message.channel.send({ embeds: [errornochannel] }); const embed = new Discord.MessageEmbed() .setDescription(`> **${supportbot.SuggestionStarter}**`) .setColor(supportbot.EmbedColour) - message.channel.send({ embed: embed }); + message.channel.send({ embeds: [embed] }); let suggestion = [] message.channel.awaitMessages(response => response.content.length > 2, { @@ -55,14 +55,14 @@ module.exports = { SuggestionMessage.setThumbnail(supportbot.SuggestionIcon_URL) } - locateChannel.send({ embed: SuggestionMessage }).then(async function(msg) { + locateChannel.send({ embeds: [SuggestionMessage] }).then(async function(msg) { msg.react(supportbot.SuggestReact_1).then(() => msg.react(supportbot.SuggestReact_2)); }); const SuggestionComplete = new Discord.MessageEmbed() .setColor(supportbot.SuccessColour) .setDescription(`:white_check_mark: Your suggestion has been successfully created. <#${locateChannel.id}>`) - message.channel.send({ embed: SuggestionComplete }) + message.channel.send({ embeds: [SuggestionComplete] }) }); diff --git a/commands/ticket.js b/commands/ticket.js index 1638b22..a24fafd 100644 --- a/commands/ticket.js +++ b/commands/ticket.js @@ -1,230 +1,242 @@ -// SupportBot, Created by Emerald Services -// Ticket Command - -const Discord = require("discord.js"); -const bot = new Discord.Client() - -const fs = require("fs") -const yaml = require('js-yaml'); - -const supportbot = yaml.load(fs.readFileSync('./supportbot-config.yml', 'utf8')); -const TicketNumberID = require('../utils/TicketNumber.js'); - -module.exports = { - name: supportbot.NewTicket, - description: supportbot.NewTicketDesc, - - async execute(message, args) { - if (!message.channel.name === supportbot.ReactionChannel || !message.channel.id === supportbot.ReactionChannel) { - if (supportbot.DeleteMessages) message.delete(); - } - - 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(`<@${message.author.id}> ${supportbot.TicketBlackListMessage}`).then(msg => { - msg.delete({timeout: 3500}) - }) - } - - // Ticket ID - let ticketNumberID = TicketNumberID.pad(message.guild.id); - - // Ticket Subject - const TicketSubject = args || supportbot.NoTicketSubject; - - const channel = await message.guild.channels.create(`${supportbot.TicketChannel}-${ticketNumberID}`); - - 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, channel.id).replace(/%ticketusername%/g, message.author.username)) - .setColor(supportbot.EmbedColour) - message.channel.send({embed: CreatedTicket}).then((r) => { - r.delete({ timeout:5000 }) - }) - } else { - const CreatedTicket = new Discord.MessageEmbed() - .setDescription(supportbot.TicketCreatedAlert.replace(/%ticketauthor%/g, message.author.id).replace(/%ticketid%/g, channel.id).replace(/%ticketusername%/g, message.author.username)) - .setColor(supportbot.EmbedColour) - message.channel.send({embed: CreatedTicket}); - } - - // Ticket Category - let TicketCategory = message.guild.channels.cache.find(category => category.name === supportbot.TicketCategory) || message.guild.channels.cache.find(category => category.id === supportbot.TicketCategory) - - // Locate Roles - let StaffMember = message.guild.roles.cache.find(SupportTeam => SupportTeam.name === supportbot.Staff) || message.guild.roles.cache.find(SupportTeam => SupportTeam.id === supportbot.Staff) - let ServerAdmins = message.guild.roles.cache.find(AdminUser => AdminUser.name === supportbot.Admin) || message.guild.roles.cache.find(AdminUser => AdminUser.id === supportbot.Admin) - - if (TicketCategory) { - channel.setParent(TicketCategory.id) - } - - channel.updateOverwrite(message.guild.id, { - SEND_MESSAGES: false, - VIEW_CHANNEL: false - }) - - channel.updateOverwrite(message.author, { - SEND_MESSAGES: true, - VIEW_CHANNEL: true - }) - - channel.updateOverwrite(StaffMember, { - SEND_MESSAGES: true, - VIEW_CHANNEL: true - }) - - channel.updateOverwrite(ServerAdmins, { - SEND_MESSAGES: true, - VIEW_CHANNEL: true - }) - - // Ticket Created, Message Sent - - if (supportbot.AllowTicketMentions) { - channel.send(`<@${message.author.id}>`) - } - - const TicketMessage = new Discord.MessageEmbed() - .setTitle(supportbot.Ticket_Title.replace(/%ticketauthor%/g, message.author.id).replace(/%ticketid%/g, channel.id).replace(/%ticketusername%/g, message.author.username)) - .setDescription(supportbot.TicketMessage.replace(/%ticketauthor%/g, message.author.id).replace(/%ticketid%/g, channel.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.') { - channel.setTopic(`Reason: ${TicketSubject} - User ID: ${message.author.id} - Ticket: ${channel.name}`) - } - - } - - const reactionMessage = await channel.send({ - embed: TicketMessage - }).then( async function(ticketmsg) { - await ticketmsg.react(supportbot.TicketLockReaction) - await ticketmsg.react(supportbot.TicketDeleteReaction) - - const collector = ticketmsg.createReactionCollector( - (reaction, user) => message.guild.roles.cache.find((staff) => staff.name === supportbot.Staff), - { dispose: true } - ); - - collector.on('collect', (reaction, user) => { - switch (reaction.emoji.name) { - case supportbot.TicketLockReaction: - - channel.updateOverwrite(message.author, { - SEND_MESSAGES: false, - VIEW_CHANNEL: true - }); - - const LockTicketEmbed = new Discord.MessageEmbed() - .setDescription(supportbot.TicketLockMessage) - .setColor(supportbot.EmbedColour) - channel.send({embed: LockTicketEmbed}) - break; - - case supportbot.TicketDeleteReaction: - const DeleteTicketEmbed = new Discord.MessageEmbed() - .setDescription(supportbot.TicketDeleteMessage) - .setColor(supportbot.EmbedColour) - channel.send({embed: DeleteTicketEmbed}) - - 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(logEmbed).catch(err => { - message.reply(err) - }) - - const TranscriptSavedEmbed = new Discord.MessageEmbed() - .setDescription(supportbot.TranscriptSavedMessage) - .setColor(supportbot.SuccessColour) - channel.send({embed: TranscriptSavedEmbed}) - - logChannel.send( new Discord.MessageAttachment( Buffer.from( html ), `${name}.html` ) ); - setTimeout(() => channel.delete(), supportbot.TicketDeleteTime); - - }) - - }).catch( () => { - m.edit('The request to close the ticket has timed out.').then( m2 => m2.delete( 3000 ) ); - }); - break; - - } - }); - - }) - - fs.writeFileSync("./storage/SupportTickets.json", '{\n "ticket": "' + channel.name + '", \n "id":' + message.author.id + "\n}", (err) => { - if (!err) return; - console.error(err) - }) - // Ticket Logs - - const errornochannel = new Discord.MessageEmbed() - .setTitle("SupportBot Error!") - .setDescription(`:x: **Error!** Channel not Found, This command cannot be executed proberbly as their is no channel within this server.\nThis is configurable via **supportbot-config.yml**\n\nChannel Required: \`${supportbot.TicketLog}\`\n\nError Code: \`SB-03\``) - .setColor(supportbot.ErrorColour); - - const TicketLogs = new Discord.MessageEmbed() - .setTitle(supportbot.TicketLog_Title) - .setThumbnail(supportbot.Ticket_Thumbnail) - .addFields( - { name: 'Ticket', value: `<#${channel.id}>` }, - { name: 'User', value: `<@${message.author.id}>` }, - ) - .setColor(supportbot.EmbedColour) - .setFooter(supportbot.EmbedFooter) - - let locateChannel = message.guild.channels.cache.find(LocateChannel => LocateChannel.name === supportbot.TicketLog) || message.guild.channels.cache.find(LocateChannel => LocateChannel.id === supportbot.TicketLog) - - if(!locateChannel) return message.channel.send({ embed: errornochannel }); - - locateChannel.send({ embed: TicketLogs }); - - - } - -} - +// SupportBot, Created by Emerald Services +// Ticket Command + +const Discord = require("discord.js"); +const { MessageButton, MessageActionRow, Permissions } = require("discord.js"); + +const fs = require("fs") +const yaml = require('js-yaml'); + +const supportbot = yaml.load(fs.readFileSync('./supportbot-config.yml', 'utf8')); +const TicketNumberID = require('../utils/TicketNumber.js'); + +async function asyncForEach(array, callback) { + for (let index = 0; index < array.length; index++) { + await callback(array[index], index, array); + } +} +module.exports = { + name: supportbot.NewTicket, + description: supportbot.NewTicketDesc, + + async execute(message, args) { + if (message.channel.name !== supportbot.ReactionChannel) { + if (supportbot.DeleteMessages) message.delete(); + } + + 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] }); + } + 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) + } + + if (supportbot.AllowTicketMentions) { + ticketChannel.send({content:`${message.author}`}) + } + + 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 MessageButton() + .setCustomId('ticketclose') + .setLabel('Close') + .setStyle(supportbot.TicketCloseColour) + .setEmoji(supportbot.TicketCloseEmoji) + + const LockButton = new MessageButton() + .setCustomId('ticketlock') + .setLabel('Lock') + .setStyle(supportbot.TicketLockColour) + .setEmoji(supportbot.TicketLockEmoji) + + const row2 = new 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 MessageButton() + .setCustomId('Department1') + .setLabel(`${supportbot.DepartmentTitle_1}`) + .setStyle(supportbot.TicketDept1Colour) + .setEmoji(supportbot.TicketDept1Emoji) + + const Department2Button = new MessageButton() + .setCustomId('Department2') + .setLabel(`${supportbot.DepartmentTitle_2}`) + .setStyle(supportbot.TicketDept2Colour) + .setEmoji(supportbot.TicketDept2Emoji) + + const Department3Button = new MessageButton() + .setCustomId('Department3') + .setLabel(`${supportbot.DepartmentTitle_3}`) + .setStyle(supportbot.TicketDept3Colour) + .setEmoji(supportbot.TicketDept3Emoji) + + const row = new 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]}) + } + } +} diff --git a/commands/transcript.js b/commands/transcript.js index 33f2a2d..7024916 100644 --- a/commands/transcript.js +++ b/commands/transcript.js @@ -33,7 +33,7 @@ module.exports = { const TranscriptSavedEmbed = new Discord.MessageEmbed() .setDescription(supportbot.ChatLogSavedMessage) .setColor(supportbot.SuccessColour) - message.channel.send({embed: TranscriptSavedEmbed}) + message.channel.send({embeds: [TranscriptSavedEmbed]}) const errornochannel = new Discord.MessageEmbed() .setTitle("SupportBot Error!") .setDescription(`:x: **Error!** Channel not Found, This command cannot be executed proberbly as their is no channel within this server.\nThis is configurable via **supportbot-config.yml**\n\nChannel Required: \`${supportbot.ChatLogChannel}\`\n\nError Code: \`SB-03\``) @@ -50,10 +50,10 @@ module.exports = { .setFooter(supportbot.EmbedFooter) let locateChannel = message.guild.channels.cache.find(LocateChannel => LocateChannel.name === supportbot.ChatLogChannel) || message.guild.channels.cache.find(LocateChannel => LocateChannel.id === supportbot.ChatLogChannel) - if(!locateChannel) return message.channel.send({ embed: errornochannel }); - - locateChannel.send( new Discord.MessageAttachment( Buffer.from( html ), `${name}.html` ) ); - locateChannel.send({ embed: ChatLogs }); + if(!locateChannel) return message.channel.send({ embeds: [errornochannel] }); + + let file = new Discord.MessageAttachment( Buffer.from( html ), `${name}.html` ) + locateChannel.send({embeds: [ChatLogs], files: [file]}) }) } diff --git a/events/interactionCreate.js b/events/interactionCreate.js new file mode 100644 index 0000000..a39bc0a --- /dev/null +++ b/events/interactionCreate.js @@ -0,0 +1,128 @@ +// SupportBot Interaction Event +// SupportBot Created by Emerald Services + +const fs = require("fs"); +const { MessageEmbed, MessageAttachment, Permissions, MessageButton, MessageActionRow } = require("discord.js"); +const yaml = require('js-yaml'); +const supportbot = yaml.load(fs.readFileSync('./supportbot-config.yml', 'utf8')); + +module.exports = async (bot, interaction, args) => { + + if (interaction.isCommand()) return; + + if(interaction.isButton()) { + if(interaction.customId === 'openticket') { + interaction.message.fetch() + interaction.deferUpdate() + let message = { + guild: bot.guilds.cache.get(interaction.message.guildId), + author: bot.users.cache.get(interaction.user.id), + content: "N/A", + channel: bot.channels.cache.get(interaction.message.channelId) + } + try { + const cmd = bot.commands.get(supportbot.NewTicket); + if(!cmd) return; + cmd.execute(message, message.content) + } + catch (error){ + console.error(error) + } + } + if(interaction.customId === 'ticketclose') { + if(interaction.channel.name.startsWith(`${supportbot.TicketChannel}-`)) { + interaction.message.fetch() + interaction.deferUpdate() + const DeleteTicketEmbed = new MessageEmbed() + .setDescription(supportbot.TicketDeleteMessage) + .setColor(supportbot.EmbedColour) + interaction.channel.send({embeds: [DeleteTicketEmbed]}) + + 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 name = interaction.channel.name; + let ticketChannel = interaction.channel + let reason = "No Reason Provided." + + interaction.channel.send({content: `**${supportbot.ClosingTicket}**`}) + .then(() => { + const logEmbed = new MessageEmbed() + .setTitle(supportbot.TranscriptTitle) + .setColor(supportbot.EmbedColour) + .setFooter(supportbot.EmbedFooter) + .addField("Closed By", user.username) + .addField("Reason", reason) + + interaction.channel.messages.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 += `-----

`; + } + }) + + const TranscriptSavedEmbed = new MessageEmbed() + .setDescription(supportbot.TranscriptSavedMessage) + .setColor(supportbot.SuccessColour) + interaction.channel.send({embeds: [TranscriptSavedEmbed]}) + + let file = new MessageAttachment( Buffer.from( html ), `${name}.html` ) + logChannel.send({embeds: [logEmbed], files: [file]}) + + setTimeout(() => interaction.channel.delete(), supportbot.TicketDeleteTime) + + }) + }) + } + } + if(interaction.customId === 'ticketlock') { + if(interaction.channel.name.startsWith(`${supportbot.TicketChannel}`)) { + interaction.message.fetch() + interaction.deferUpdate() + let Admin = interaction.guild.roles.cache.find(AdminUser => AdminUser.name === supportbot.Admin) || interaction.guild.roles.cache.find(AdminUser => AdminUser.id === supportbot.Admin) + let all = interaction.channel.permissionOverwrites.cache + + let parent = interaction.guild.channels.cache.find(c => c.name === `${supportbot.LockTicketCategory}`) || interaction.guild.channels.cache.find(c => c.id === `${supportbot.LockTicketCategory}`) + if(parent) { + interaction.channel.setParent(parent.id) + } + + all.forEach(perm => { + interaction.channel.permissionOverwrites.delete(perm.id) + + }) + interaction.channel.permissionOverwrites.create(Admin.id, {VIEW_CHANNEL: true}) + + interaction.channel.permissionOverwrites.create(interaction.guild.id, {VIEW_CHANNEL: false}) + + + const ticketDeleteButton = new MessageButton() + .setCustomId('ticketclose') + .setLabel('Close') + .setStyle(supportbot.TicketDeleteColour) + .setEmoji(supportbot.TicketDeleteEmoji) + + const row = new MessageActionRow() + .addComponents(ticketDeleteButton) + const ArchiveEmbed = new MessageEmbed() + .setTitle("Archived") + .setDescription(`Archived ${interaction.channel.name}`) + .setColor(`${supportbot.SuccessColour}`) + + interaction.channel.send({embeds: [ArchiveEmbed]}) + interaction.message.edit({components: [row]}) + } + } + } + +} \ No newline at end of file diff --git a/events/message.js b/events/messageCreate.js similarity index 100% rename from events/message.js rename to events/messageCreate.js diff --git a/events/ready.js b/events/ready.js index 67b683c..be7d7f3 100644 --- a/events/ready.js +++ b/events/ready.js @@ -3,17 +3,17 @@ const Discord = require("discord.js"); const fs = require("fs"); +const { MessageActionRow, MessageButton } = require('discord.js'); const yaml = require('js-yaml'); const supportbot = yaml.load(fs.readFileSync('./supportbot-config.yml', 'utf8')); const tickets = yaml.load(fs.readFileSync('./storage/ticketreaction.yml', 'utf8')); -module.exports = async (bot) => { +module.exports = async bot => { bot.user.setActivity(supportbot.BotActivity, { type: supportbot.ActivityType, - url: supportbot.StreamingURL - + url: supportbot.StreamingURL }); console.log(`\u001b[32m`, `┏━━━┓╋╋╋╋╋╋╋╋╋╋╋╋╋┏┓┏━━┓╋╋╋┏┓`) @@ -24,21 +24,21 @@ module.exports = async (bot) => { console.log(`\u001b[32m`, `┗━━━┻━━┫┏━┫┏━┻━━┻┛┗━┻━━━┻━━┻━┛`) console.log(`\u001b[32m`, `┗╋╋╋╋╋╋╋┃┃╋┃┃`) console.log(`\u001b[32m`, `╋╋╋╋╋╋╋┗┛╋┗┛`) - console.log(` `) + console.log(` `) console.log(`\u001b[31m`, `――――――――――――――――――――――――――――――――――――――――――――`) - console.log(` `) + console.log(` `) console.log(`\u001b[33m`, `${supportbot.Bot_Name} v${supportbot.SupportBot_Version}`, `\u001b[36m`, `Connected to Discord`) - console.log(`\u001b[33m`, `Documentation:`, `\u001b[36m`, `https://docs.emeraldsrv.dev`) + console.log(`\u001b[33m`, `Documentation:`, `\u001b[36m`, `https://supportbot.emeraldsrv.dev`) console.log(`\u001b[33m`, `Discord:`, `\u001b[36m`, `https://emeraldsrv.dev/discord`) console.log(`\u001b[33m`, `Hosting:`, `\u001b[36m`, `https://emeraldsrv.dev/hosting`) - console.log(` `) + console.log(` `) console.log(`\u001b[37m`, `SupportBot proudly created by Emerald Services`) - console.log(` `) + console.log(` `) console.log(`\u001b[31m`, `――――――――――――――――――――――――――――――――――――――――――――`) - if (supportbot.ReactionTickets === true) { + if (supportbot.ReactionTickets) { let chan1 = bot.channels.cache.find(channel => channel.name === supportbot.ReactionChannel) if (!chan1) { @@ -46,26 +46,36 @@ module.exports = async (bot) => { return false; } - chan1.messages.fetch(tickets.ReactionMessage_ID).catch(r => { + chan1.messages.fetch(tickets.ReactionMessage_ID).catch(async r => { let embed = new Discord.MessageEmbed() .setTitle(supportbot.ReactionMessage.replace(/%reaction_emoji%/g, supportbot.ReactionEmoji)) .setColor(supportbot.SuccessColour) .setFooter(supportbot.EmbedFooter); - if (supportbot.ReactionPanel_Description === true) { + if (supportbot.ReactionPanel_Description) { embed.setDescription(supportbot.ReactionDescription) } - if (supportbot.ReactionPanel_Thumbnail === true) { + if (supportbot.ReactionPanel_Thumbnail) { embed.setThumbnail(supportbot.ReactionThumbnail) } - if (supportbot.ReactionPanel_Image === true) { + if (supportbot.ReactionPanel_Image) { embed.setImage(supportbot.ReactionImage) } + + let button = new MessageButton() + .setLabel('Open Ticket') + .setCustomId('openticket') + .setStyle('PRIMARY') + + let row = new MessageActionRow() + .addComponents(button) + - bot.channels.cache.find(channel => channel.name === supportbot.ReactionChannel).send({ - embed: embed + await chan1.send({ + embeds: [embed], + components: [row] }).then(r => { let data = { "ReactionMessage_ID": `${r.id}` @@ -73,12 +83,10 @@ module.exports = async (bot) => { let yamlStr = yaml.dump(data); fs.writeFileSync('./storage/ticketreaction.yml', yamlStr, 'utf8'); - r.react(supportbot.ReactionEmoji); }).catch(e => { - console.log(e) + console.log("Raw"+e) }) }) } - }; diff --git a/index.js b/index.js index 3c7f7f3..338a38d 100755 --- a/index.js +++ b/index.js @@ -9,11 +9,18 @@ // // Discord Support: https://emeraldsrv.dev/discord -const Discord = require("discord.js"); -const fs = require("fs"); -const bot = new Discord.Client(); +// const Discord = require("discord.js"); +const { Client, Intents, Collection } = require("discord.js"); -bot.commands = new Discord.Collection(); +const fs = require("fs"); + +const bot = new Client({ + intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] +}); + +const { REST } = require('@discordjs/rest'); + +bot.commands = new Collection(); const yaml = require('js-yaml'); const supportbot = yaml.load(fs.readFileSync('./supportbot-config.yml', 'utf8')); @@ -50,7 +57,7 @@ const init = async () => { init(); -fs.readdir("./commands/", (err, files) => { +fs.readdir("./commands/", async (err, files) => { console.info(`\u001b[36m`, `➢ SupportBot Commands`); console.info(` `); @@ -70,7 +77,7 @@ fs.readdir("./commands/", (err, files) => { console.info(`\u001b[32m`, `[${supportbot.Bot_Name}]:`, `\u001b[36m`, `#${i + 1} Command Loaded: ${props.name.toProperCase()}`); bot.commands.set(props.name, props); }); - + console.info(`\u001b[32m`, `[${supportbot.Bot_Name}]:`, `\u001b[36m`, `Loaded ${jsfiles.length} commands!`); console.log(`\u001b[31m`, `――――――――――――――――――――――――――――――――――――――――――――`) console.log(` `) diff --git a/package.json b/package.json index a5333fe..0b232a2 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,9 @@ "author": "Emerald Services", "license": "MIT", "dependencies": { - "discord.js": "^12.5.3", + "@discordjs/rest": "^0.1.0-canary.0", + "discord-api-types": "^0.23.1", + "discord.js": "^13.1.0", "js-yaml": "^4.1.0", "jsdom": "^16.7.0" } diff --git a/storage/TicketID.json b/storage/TicketID.json index 0967ef4..c69b1e8 100755 --- a/storage/TicketID.json +++ b/storage/TicketID.json @@ -1 +1,8 @@ -{} +{ + "854057237495676938": { + "id": 21 + }, + "597779408295821323": { + "id": 1 + } +} \ No newline at end of file diff --git a/supportbot-config.yml b/supportbot-config.yml index 5b138e2..eac4934 100755 --- a/supportbot-config.yml +++ b/supportbot-config.yml @@ -9,14 +9,14 @@ # # Discord Support: https://emeraldsrv.dev/discord -SupportBot_Version: "7.1" +SupportBot_Version: "7.2" # ------------------------- # General Configuration # ------------------------- -Token: "BOT_TOKEN_HERE" -Prefix: "!" +Token: "BOT_TOKEN" +Prefix: "-" Bot_Name: "SupportBot" DeleteMessages: true @@ -26,7 +26,7 @@ DeleteMessages: true # Activity Configuration # ------------------------- -BotActivity: "-help | SupportBot" +BotActivity: "Need Help? -ticket" StreamingURL: "https://www.twitch.tv/YOUR_TWITCH_NAME" # Set The ActivityType to "STREAMING" for a streaming status! @@ -39,7 +39,7 @@ ActivityType: "PLAYING" # ------------------------- EmbedColour: "#f74343" -EmbedFooter: "SupportBot | The #1 Supportive Discord Bot" +EmbedFooter: "SupportBot | An Advanced Ticket System" ErrorColour: "#d12519" SuccessColour: "#04b545" @@ -60,18 +60,14 @@ AutoRole: true AutoRole_Role: "Member" LockdownRole: "@everyone" -Staff: "Staff" -Admin: "Admin" +Staff: "Server Staff" +Admin: "Server Admin" TicketBlackListRole: "Blacklisted" - # ------------------------- # Tickets Configuration # ------------------------- -# --- General Config --- -# --- Start --- - -TicketCategory: "▬▬ TICKETS ▬▬" +TicketCategory: "Support Tickets" TicketChannel: "ticket" TicketLog: "ticket-logs" @@ -129,20 +125,67 @@ AddedUser: "👍 <@%user%> has been added to this ticket" RemovedUser: "👍 <@%user%> has been removed from this ticket" +# --- Buttons Config --- +# --- Start --- + +# Discord Button Colour Selection +# PRIMARY - Blurple +# DANGER - Red +# SUCCESS - Green +# Secondary - Grey + TicketLockReaction: "🔒" TicketDeleteReaction: "⛔" +LockTicketCategory: "Archive" + +TicketCloseEmoji: "❌" +TicketDeleteEmoji: "⛔" +TicketLockEmoji: "🔒" + +TicketCloseColour: "DANGER" +TicketDeleteColour: "DANGER" +TicketLockColour: "PRIMARY" + +TicketDept1Colour: "PRIMARY" +TicketDept2Colour: "PRIMARY" +TicketDept3Colour: "PRIMARY" + +TicketDept1Emoji: "1️⃣" +TicketDept2Emoji: "2️⃣" +TicketDept3Emoji: "3️⃣" TranscriptSavedMessage: "📝 **Transcript Saved!**" TicketLockMessage: "❌ **Ticket Locked!**" TicketDeleteMessage: "⚠ **Ticket Deleting!**" # Tickets deleting after 5 seconds by default. TicketDeleteTime: 5000 # Time must be set in miliseconds. +# --- Departments Config --- +# --- Start --- + +TicketDepartments: true + +AllowStaff: true +# If set to false users with the "Staff" role will not be able to view tickets +# without a valid department role set below. + +# Set to false to allow "Staff" to see tickets whether its a department for them or not. + +DepartmentTitle_1: "Support" +DepartmentTitle_2: "Billing" +DepartmentTitle_3: "Marketing" +# Ticket department title, This is the title for a ticket department to help users know what is available. + +DepartmentRole_1: "Support Team" +DepartmentRole_2: "Billing Team" +DepartmentRole_3: "Marketing Team" +# Ticket roles are the roles that will be able to gain access to tickets depending on what department has been choosen. + # --- Closing Config --- # --- Start --- ClosingTicket: ":warning: You have requested to close your support ticket." ClosingConfirmation_Word: "confirm" -CloseConfirmation: true +CloseConfirmation: false # -------------------------------- # System Messages Configuration @@ -297,4 +340,4 @@ IncorrectPerms: ":x: **Err!** You do not have the correct permissions to use thi InvalidChannel: ":x: **Err!** Channel not found. Please create it!" UserNotFound: ":x: **Err!** This user doesn't exist, Are they in this server?" NoValidTicket: ":warning: You cannot execute this command here. This command is used when closing a ticket." -TicketExists: ":warning: This ticket cannot be opened, It already exists!" +TicketExists: ":warning: This ticket cannot be opened, It already exists!" \ No newline at end of file