diff --git a/commands/add.js b/commands/add.js index 404d198..c4bbbc0 100644 --- a/commands/add.js +++ b/commands/add.js @@ -7,24 +7,19 @@ module.exports = () => { client.on("messageCreate",msg => { if (!msg.content.startsWith(config.prefix+"add")) return var user = msg.mentions.users.first() - if (!user){ - return msg.channel.send({content:"**There is no user to add:**\nuse: `"+config.prefix+"add `"}) - } + if (!user) return msg.channel.send({embeds:[bot.errorLog.invalidArgsMessage("Missing Argument ``:\n`"+config.prefix+"add `")]}) if (!msg.member.permissions.has("MANAGE_CHANNELS") && !msg.member.permissions.has("ADMINISTRATOR")){ - return msg.channel.send({content:"You have no permissions to add someone to the channel!\nYou need the `ADMINISTRATOR` or `MANAGE_CHANNELS` permission"}) + return msg.channel.send({embeds:[bot.errorLog.noPermsMessage]}) } msg.channel.messages.fetchPinned().then(msglist => { var firstmsg = msglist.last() - if (firstmsg == undefined || firstmsg.author.id != client.user.id){ - msg.channel.send({content:"You are not in a ticket!"}) - return - } + if (firstmsg == undefined || firstmsg.author.id != client.user.id) return msg.channel.send({embeds:[bot.errorLog.notInATicket]}) msg.channel.permissionOverwrites.create(user.id, { VIEW_CHANNEL:true, ADD_REACTIONS:true,ATTACH_FILES:true, EMBED_LINKS:true, SEND_MESSAGES:true}) - msg.channel.send({content:"Added "+user.tag+" to the ticket"}) + msg.channel.send({embeds:[bot.errorLog.success("User Added!",user.tag+" is added to this ticket")]}) if (config.logs){console.log("[system] added user to ticket (name:"+user.username+",ticket:"+msg.channel.name+")")} var loguser = msg.mentions.users.first() @@ -37,23 +32,21 @@ module.exports = () => { if (!interaction.isCommand()) return if (interaction.commandName != "add") return const user = interaction.options.getUser("user") - const member = client.guilds.cache.find(g => g.id == interaction.guild.id).members.cache.find(m => m.id == interaction.member.id) - if (!member.permissions.has("MANAGE_CHANNELS") && !member.permissions.has("ADMINISTRATOR")){ - return interaction.reply({content:"You have no permissions to add someone to the channel!\nYou need the `ADMINISTRATOR` or `MANAGE_CHANNELS` permission"}) - } + const permsmember = client.guilds.cache.find(g => g.id == interaction.guild.id).members.cache.find(m => m.id == interaction.member.id) + if (config.main_adminroles.some((item)=>{return interaction.guild.members.cache.find((m) => m.id == interaction.member.id).roles.cache.has(item)}) == false && permsmember.permissions.has("ADMINISTRATOR")){ + interaction.reply({embeds:[bot.errorLog.noPermsMessage]}) + return + } interaction.channel.messages.fetchPinned().then(msglist => { var firstmsg = msglist.last() - if (firstmsg == undefined || firstmsg.author.id != client.user.id){ - interaction.reply({content:"You are not in a ticket!"}) - return - } + if (firstmsg == undefined || firstmsg.author.id != client.user.id) return interaction.reply({embeds:[bot.errorLog.notInATicket]}) interaction.channel.permissionOverwrites.create(user.id, { VIEW_CHANNEL:true, ADD_REACTIONS:true,ATTACH_FILES:true, EMBED_LINKS:true, SEND_MESSAGES:true}) - interaction.reply({content:"Added "+user.tag+" to the ticket"}) + interaction.reply({embeds:[bot.errorLog.success("User Added!",user.tag+" is added to this ticket")]}) if (config.logs){console.log("[system] added user to ticket (name:"+user.username+",ticket:"+interaction.channel.name+")")} var loguser = user diff --git a/commands/close.js b/commands/close.js index 6e90c86..5601c25 100644 --- a/commands/close.js +++ b/commands/close.js @@ -11,10 +11,7 @@ module.exports = () => { msg.channel.messages.fetchPinned().then(msglist => { var firstmsg = msglist.last() - if (firstmsg == undefined || firstmsg.author.id != client.user.id){ - msg.channel.send({content:"You are not in a ticket!"}) - return - } + if (firstmsg == undefined || firstmsg.author.id != client.user.id) return msg.channel.send({embeds:[bot.errorLog.notInATicket]}) const closebutton = new discord.MessageActionRow() .addComponents([ @@ -25,7 +22,7 @@ module.exports = () => { .setEmoji("🔒") ]) - msg.channel.send({content:"**Click on the button below to close this ticket!**",components:[closebutton]}) + msg.channel.send({embeds:[bot.errorLog.success("Close this ticket!","You can close this ticket by clicking on the button below!")],components:[closebutton]}) console.log("[system] closed a ticket via command") @@ -41,10 +38,7 @@ module.exports = () => { interaction.channel.messages.fetchPinned().then(msglist => { var firstmsg = msglist.last() - if (firstmsg == undefined || firstmsg.author.id != client.user.id){ - interaction.reply({content:"You are not in a ticket!"}) - return - } + if (firstmsg == undefined || firstmsg.author.id != client.user.id) return interaction.reply({embeds:[bot.errorLog.notInATicket]}) const closebutton = new discord.MessageActionRow() .addComponents([ @@ -55,7 +49,7 @@ module.exports = () => { .setEmoji("🔒") ]) - interaction.reply({content:"**Click on the button below to close this ticket!**",components:[closebutton]}) + interaction.reply({embeds:[bot.errorLog.success("Close this ticket!","You can close this ticket by clicking on the button below!")],components:[closebutton]}) console.log("[system] closed a ticket via command") diff --git a/commands/delete.js b/commands/delete.js index f0b7305..72e2baf 100644 --- a/commands/delete.js +++ b/commands/delete.js @@ -11,10 +11,7 @@ module.exports = () => { msg.channel.messages.fetchPinned().then(msglist => { var firstmsg = msglist.last() - if (firstmsg == undefined || firstmsg.author.id != client.user.id){ - msg.channel.send({content:"You are not in a ticket!"}) - return - } + if (firstmsg == undefined || firstmsg.author.id != client.user.id) return msg.channel.send({embeds:[bot.errorLog.notInATicket]}) const closebutton = new discord.MessageActionRow() .addComponents([ @@ -25,7 +22,7 @@ module.exports = () => { .setEmoji("❌") ]) - msg.channel.send({content:"**Click on the button below to delete this ticket!**",components:[closebutton]}) + msg.channel.send({embeds:[bot.errorLog.success("Delete this ticket!","You can delete this ticket by clicking on the button below!")],components:[closebutton]}) console.log("[system] deleted a ticket via command") @@ -41,10 +38,7 @@ module.exports = () => { interaction.channel.messages.fetchPinned().then(msglist => { var firstmsg = msglist.last() - if (firstmsg == undefined || firstmsg.author.id != client.user.id){ - interaction.reply({content:"You are not in a ticket!"}) - return - } + if (firstmsg == undefined || firstmsg.author.id != client.user.id) return interaction.reply({embeds:[bot.errorLog.notInATicket]}) const closebutton = new discord.MessageActionRow() .addComponents([ @@ -55,7 +49,7 @@ module.exports = () => { .setEmoji("❌") ]) - interaction.reply({content:"**Click on the button below to delete this ticket!**",components:[closebutton]}) + interaction.reply({embeds:[bot.errorLog.success("Delete this ticket!","You can delete this ticket by clicking on the button below!")],components:[closebutton]}) console.log("[system] deleted a ticket via command") diff --git a/commands/remove.js b/commands/remove.js index 7f15655..3096d61 100644 --- a/commands/remove.js +++ b/commands/remove.js @@ -7,24 +7,19 @@ module.exports = () => { client.on("messageCreate",msg => { if (!msg.content.startsWith(config.prefix+"remove")) return var user = msg.mentions.users.first() - if (!user){ - return msg.channel.send({content:"**There is no user to remove:**\nuse: `"+config.prefix+"remove `"}) - } + if (!user) return msg.channel.send({embeds:[bot.errorLog.invalidArgsMessage("Missing Argument ``:\n`"+config.prefix+"remove `")]}) if (!msg.member.permissions.has("MANAGE_CHANNELS") && !msg.member.permissions.has("ADMINISTRATOR")){ - return msg.channel.send({content:"You have no permissions to remove someone from the channel!\nYou need the `ADMINISTRATOR` or `MANAGE_CHANNELS` permission"}) + return msg.channel.send({embeds:[bot.errorLog.noPermsMessage]}) } msg.channel.messages.fetchPinned().then(msglist => { var firstmsg = msglist.last() - if (firstmsg == undefined || firstmsg.author.id != client.user.id){ - msg.channel.send({content:"You are not in a ticket!"}) - return - } + if (firstmsg == undefined || firstmsg.author.id != client.user.id) return msg.channel.send({embeds:[bot.errorLog.notInATicket]}) msg.channel.permissionOverwrites.delete(user.id) - msg.channel.send({content:"Deleted "+user.tag+" from the ticket"}) + msg.channel.send({embeds:[bot.errorLog.success("User removed!",user.tag+" is removed from this ticket")]}) if (config.logs){console.log("[system] deleted user from ticket (name:"+user.username+",ticket:"+msg.channel.name+")")} var loguser = msg.mentions.users.first() @@ -37,23 +32,22 @@ module.exports = () => { if (!interaction.isCommand()) return if (interaction.commandName != "remove") return const user = interaction.options.getUser("user") - const member = client.guilds.cache.find(g => g.id == interaction.guild.id).members.cache.find(m => m.id == interaction.member.id) - if (!member.permissions.has("MANAGE_CHANNELS") && !member.permissions.has("ADMINISTRATOR")){ - return interaction.reply({content:"You have no permissions to remove someone from the channel!\nYou need the `ADMINISTRATOR` or `MANAGE_CHANNELS` permission"}) - } + const permsmember = client.guilds.cache.find(g => g.id == interaction.guild.id).members.cache.find(m => m.id == interaction.member.id) + if (config.main_adminroles.some((item)=>{return interaction.guild.members.cache.find((m) => m.id == interaction.member.id).roles.cache.has(item)}) == false && permsmember.permissions.has("ADMINISTRATOR")){ + interaction.reply({embeds:[bot.errorLog.noPermsMessage]}) + return + } + interaction.channel.messages.fetchPinned().then(msglist => { var firstmsg = msglist.last() - if (firstmsg == undefined || firstmsg.author.id != client.user.id){ - interaction.reply({content:"You are not in a ticket!"}) - return - } + if (firstmsg == undefined || firstmsg.author.id != client.user.id) return interaction.reply({embeds:[bot.errorLog.notInATicket]}) interaction.channel.permissionOverwrites.delete(user.id) - interaction.reply({content:"Deleted "+user.tag+" from the ticket"}) + interaction.reply({embeds:[bot.errorLog.success("User removed!",user.tag+" is removed from this ticket")]}) if (config.logs){console.log("[system] removed user from ticket (name:"+user.username+",ticket:"+interaction.channel.name+")")} var loguser = user diff --git a/commands/rename.js b/commands/rename.js index e3333e4..d5bf6bd 100644 --- a/commands/rename.js +++ b/commands/rename.js @@ -10,17 +10,17 @@ module.exports = () => { msg.channel.messages.fetchPinned().then(msglist => { var firstmsg = msglist.last() - if (firstmsg == undefined || firstmsg.author.id != client.user.id){ - msg.channel.send({content:"You are not in a ticket!"}) - return - } + if (firstmsg == undefined || firstmsg.author.id != client.user.id) return msg.channel.send({embeds:[bot.errorLog.notInATicket]}) if (!msg.member.permissions.has("MANAGE_CHANNELS") && !msg.member.permissions.has("ADMINISTRATOR")){ - return msg.channel.send({content:"You have no permissions to change the channel name!\nYou need the `ADMINISTRATOR` or `MANAGE_CHANNELS` permission"}) + return msg.channel.send({embeds:[bot.errorLog.noPermsMessage]}) } var newname = msg.content.split(config.prefix+"rename")[1].substring(1) + + if (!newname) return msg.channel.send({embeds:[bot.errorLog.invalidArgsMessage("Missing Argument ``:\n`"+config.prefix+"rename `")]}) + var name = msg.channel.name var prefix = "" const tickets = config.options @@ -33,7 +33,7 @@ module.exports = () => { if (!prefix) prefix = "noprefix-" msg.channel.setName(prefix+newname) - msg.channel.send({content:"**The name is changed!**\nWarning: you can only change the channel name 2 times per minute! (this is due discord rate limits)"}) + msg.channel.send({embeds:[bot.errorLog.success("The name has changed!","Warning: you can only change the channel name 2 times per minute!\n(this is due discord rate limits)")]}) console.log("[system] renamed a ticket via command") @@ -49,14 +49,12 @@ module.exports = () => { interaction.channel.messages.fetchPinned().then(msglist => { var firstmsg = msglist.last() - if (firstmsg == undefined || firstmsg.author.id != client.user.id){ - interaction.reply({content:"You are not in a ticket!"}) - return - } + if (firstmsg == undefined || firstmsg.author.id != client.user.id)return interaction.reply({embeds:[bot.errorLog.notInATicket]}) - const member = client.guilds.cache.find(g => g.id == interaction.guild.id).members.cache.find(m => m.id == interaction.member.id) - if (!member.permissions.has("MANAGE_CHANNELS") && !member.permissions.has("ADMINISTRATOR")){ - return interaction.reply({content:"You have no permissions to change the channel name!\nYou need the `ADMINISTRATOR` or `MANAGE_CHANNELS` permission"}) + const permsmember = client.guilds.cache.find(g => g.id == interaction.guild.id).members.cache.find(m => m.id == interaction.member.id) + if (config.main_adminroles.some((item)=>{return interaction.guild.members.cache.find((m) => m.id == interaction.member.id).roles.cache.has(item)}) == false && permsmember.permissions.has("ADMINISTRATOR")){ + interaction.reply({embeds:[bot.errorLog.noPermsMessage]}) + return } var newname = interaction.options.getString("name") @@ -72,7 +70,7 @@ module.exports = () => { if (!prefix) prefix = "noprefix-" interaction.channel.setName(prefix+newname) - interaction.reply({content:"**The name is changed!**\nWarning: you can only change the channel name 2 times per minute! (this is due discord rate limits)"}) + interaction.reply({embeds:[bot.errorLog.success("The name has changed!","Warning: you can only change the channel name 2 times per minute!\n(this is due discord rate limits)")]}) console.log("[system] renamed a ticket via command") diff --git a/commands/ticket.js b/commands/ticket.js index f76af3c..62d15dc 100644 --- a/commands/ticket.js +++ b/commands/ticket.js @@ -18,14 +18,14 @@ module.exports = () => { client.on("messageCreate", msg => { if (msg.content.startsWith(config.prefix+"msg")){ if (config.main_adminroles.some((item)=>{return msg.member.roles.cache.has(item)}) == false){ - msg.channel.send({content:"You have no permission to run this command!"}) + msg.channel.send({embeds:[bot.errorLog.noPermsMessage]}) return } const id = msg.content.split(config.prefix+"msg")[1].substring(1) ? msg.content.split(config.prefix+"msg")[1].substring(1) : false - if (!id) return msg.channel.send({content:"**There is no id!**\nUse: `"+config.prefix+"msg `"}) - if (!msgIds.includes(id)) return msg.channel.send({content:"**Invalid id!**\nChoose from this list:\n_"+msgIds.join("_\n_")+"_"}) + if (!id) return msg.channel.send({embeds:[bot.errorLog.invalidArgsMessage("Missing Argument ``:\n`"+config.prefix+"msg `")]}) + if (!msgIds.includes(id)) return msg.channel.send({embeds:[bot.errorLog.invalidIdChooseFromList(msgIds)]}) const {embed,componentRows} = require("../core/ticketMessageEmbed").createEmbed(id) @@ -41,14 +41,15 @@ module.exports = () => { if (!interaction.isCommand()) return if (interaction.commandName != "message") return - if (config.main_adminroles.some((item)=>{return interaction.guild.members.cache.find((m) => m.id == interaction.member.id).roles.cache.has(item)}) == false){ - interaction.reply({content:"You have no permission to run this command!"}) + const permsmember = client.guilds.cache.find(g => g.id == interaction.guild.id).members.cache.find(m => m.id == interaction.member.id) + if (config.main_adminroles.some((item)=>{return interaction.guild.members.cache.find((m) => m.id == interaction.member.id).roles.cache.has(item)}) == false && permsmember.permissions.has("ADMINISTRATOR")){ + interaction.reply({embeds:[bot.errorLog.noPermsMessage]}) return } const id = interaction.options.getString("id") - if (!msgIds.includes(id)) return interaction.reply({content:"**Invalid id!**\nChoose from this list:\n_"+msgIds.join("_\n_")+"_"}) + if (!msgIds.includes(id)) return interaction.reply({embeds:[bot.errorLog.invalidIdChooseFromList(msgIds)]}) const {embed,componentRows} = require("../core/ticketMessageEmbed").createEmbed(id) diff --git a/core/errorLogSystem.js b/core/errorLogSystem.js new file mode 100644 index 0000000..4b4df0d --- /dev/null +++ b/core/errorLogSystem.js @@ -0,0 +1,60 @@ +const discord = require('discord.js') +const bot = require('../index') +const client = bot.client +const config = bot.config + +const loadChalk = async () => { + return await (await import("chalk")).default +} +const embed = discord.MessageEmbed + +exports.noPermsMessage = new embed() + .setColor("RED") + .setTitle(":x: No Permissions! :x:") + .setDescription("You don't have the correct roles to run this command!\nYou need the `ADMINISTRATOR` permission or be in the list of allowed roles!") + +/**@param {String} message */ +exports.invalidArgsMessage = (message) => { + var x = new embed() + .setColor("RED") + .setTitle(":x: Invalid Arguments! :x:") + .setDescription(message) + + return x +} + +/**@param {String} message */ +exports.serverError = (message) => { + var x = new embed() + .setColor("ORANGE") + .setTitle(":warning: Bot Error! :warning:") + .setDescription(message) + + return x +} + +/**@param {String[]} list */ +exports.invalidIdChooseFromList = (list) => { + var x = new embed() + .setColor("RED") + .setTitle(":x: Invalid ID :x:") + .setDescription("Choose one of the id's below:\n`"+list.join("`\n`")+"`") + return x +} + + +//seves +exports.notInATicket = new embed() + .setColor("RED") + .setTitle(":x: You are not in a ticket! :x:") + .setDescription("This command doesn't work outside tickets!") + + +exports.success = (title,message) => { + var x = new embed() + .setColor(config.main_color) + .setTitle(":white_check_mark: "+title+" :white_check_mark:") + .setDescription(message) + + return x +} \ No newline at end of file diff --git a/core/reactionRoles.js b/core/reactionRoles.js index 0e288b4..9be8f22 100644 --- a/core/reactionRoles.js +++ b/core/reactionRoles.js @@ -50,7 +50,7 @@ module.exports = async () => { } }catch{ - interaction.reply({ephemeral:true,content:"Something went wrong! Contact the owner of this bot for more information"}) + interaction.replyinteraction.channel.send({embeds:[bot.errorLog.serverError("Something went wrong!**\nPlease try again another time!")]}) } }) } \ No newline at end of file diff --git a/core/ticketCloser.js b/core/ticketCloser.js index cce6df6..76de474 100644 --- a/core/ticketCloser.js +++ b/core/ticketCloser.js @@ -147,7 +147,7 @@ exports.runThis = () => { if (fileattachment == false){ console.log("[transcript] internal error: no transcript is created!") - interaction.channel.send({content:"**Something went wrong while making the transcript!**\nPlease try again another time!"}) + interaction.channel.send({embeds:[bot.errorLog.serverError("Something went wrong while making the transcript!**\nPlease try again another time!")]}) return } diff --git a/index.js b/index.js index cdd360c..4e546eb 100644 --- a/index.js +++ b/index.js @@ -23,6 +23,7 @@ if (isDev){ } }else{var config = require('./config.json')} exports.config = config +exports.errorLog = require("./core/errorLogSystem") client.on('ready',async () => { const chalk = await (await import("chalk")).default