const Discord = require("discord.js"); const db = require("quick.db"); const custom = require("../models/custom.js"); module.exports.run = async (client, message, args) => { if (!message.member.permissions.has("MANAGE_GUILD") && message.author.id !== "606279329844035594") return message.channel.send("You do not have manage guild permission"); if(args[0] === "view".toLowerCase()){ custom.find({ Command: "all", Guild: message.guild.id }).exec((err,res) => { if(err) message.channel.send(err) let page = Math.ceil(res.length / 10) let embed = new Discord.MessageEmbed() .setTitle("Custom commands") let pg = parseInt(args[1]) if(pg !== Math.floor(pg)) pg = 1; if(!pg) pg = 1; let end = pg * 10; let start = (pg * 10) -10; if(res.length === 0){ embed.addField("Error", "No pages found") } else if(res.length <= start){ embed.addField("Error", "Page not found") }else if(res.length <= end){ embed.setFooter(`Page ${pg}/${page}`) for(let i = start; i <= res.length; i++){ embed.addField(`${i + 1} command`,`${res[i].Command}`) } }else{ embed.setFooter(`Page ${pg}/${page}`) for(let i = start; i < end; i++){ embed.addField(`${i + 1} command`,`${res[i].Command}`) } } message.channel.send(embed) }) } else if(args[0] === "delete".toLowerCase()){ if (!args[1]) return message.channel.send( `Please supply the name for the custom command you want to delete` ); custom.findOne( { Command: args[1], Guild: message.guild.id }, async (err, data) => { if (err) throw err; if (!data) return message.channel.send(`That is not a custom command`); custom.findOneAndDelete( { Command: args[1], Guild: message.guild.id }, (err) => { if (err) throw err; } ); let embed = new Discord.MessageEmbed() .setTitle("Custom command delete") .setColor("#FF9966") .setDescription(`Successfully deleted the custom command ${args[1]}`) return message.channel.send(embed); } ); }else if(args[0] === "create".toLowerCase()){ if (!args[1]) return message.channel.send(`Please specify a name for the custom command`); if (!args.slice(2).join(" ")) return message.channel.send( `Please specify content for the custom command` ); custom.findOne( { Guild: message.guild.id, Command: args[1] }, async (err, data) => { let embed = new Discord.MessageEmbed() .setTitle("Custom command update") .setDescription( `Name: ${args[1]}\n New Contents: ${args.slice(2).join(" ")}` ) .setColor("#FF9966"); if (err) throw err; if (data) { data.Content = args.slice(2).join(" "); data.save(); message.channel.send(embed); } else if (!data) { let newData = new custom({ Guild: message.guild.id, Command: args[1], Content: args.slice(2).join(" ") }); newData.save(); let embed2 = new Discord.MessageEmbed() .setTitle("Custom command create") .setDescription(`Name: ${args[1]}\nContents: ${args.slice(2).join(" ")}`) .setColor("#FF9966"); message.channel.send( embed2 ); } } ); }else{ return message.reply("Please only use view or create or delete for the custom commands") } }; module.exports.help = { name: "cc", description: "Creates a custom command", usage: " ", owner: false, aliases: ["customcommand"] };