Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module.exports = function (Bot,msg){
- if (!msg.content.startsWith(Bot.Config.Bot.prefix) || msg.author.bot) return
- // Check if command exists
- const args = msg.content.slice(Bot.Config.Bot.prefix.length).split(/ +/)
- const commandName = args.shift().toLowerCase()
- const command = Bot.Commands.get(commandName) || Bot.Commands.find(command => command.aliases && command.aliases.includes(commandName))
- if (!command) return
- if (!command.module) return
- // Guildonly check
- if (command.guildOnly && msg.channel.type !== "text") {
- const Embed = new Bot.Discord.RichEmbed()
- .setColor("#ff0000")
- .setTitle("`"+commandName+"` can only be used inside of servers.")
- .setFooter("Requested by "+msg.author.tag, msg.author.avatarURL)
- return msg.channel.send(Embed)
- } else if (command.guildOnly && msg.channel.type == "text" &! Bot.Config[msg.guild.id]) {
- const Embed = new Bot.Discord.RichEmbed()
- .setColor("#ff0000")
- .setTitle("There was an issue with running `"+commandName+"`")
- .setDescription("This command can only be used inside of guilds, and this guild's configuration isn't set up properly!")
- .setFooter("Requested by "+msg.author.tag, msg.author.avatarURL)
- return msg.channel.send(Embed)
- }
- // Cooldown check
- if (!Bot.Cooldowns.has(command.name)) {
- Bot.Cooldowns.set(command.name, new Bot.Discord.Collection())
- }
- const now = Date.now()
- const timestamps = Bot.Cooldowns.get(command.name)
- const cooldownAmount = (command.cooldown || Bot.Config.Bot.command_cooldown) * 1000
- if (timestamps.has(msg.author.id)) {
- const expirationTime = timestamps.get(msg.author.id) + cooldownAmount
- if (now < expirationTime) {
- const timeLeft = (expirationTime - now) / 1000
- const Embed = new Bot.Discord.RichEmbed()
- .setColor("#ff0000")
- .setTitle("Please wait "+timeLeft.toFixed(1)+" more seconds before using `"+commandName+"`!")
- .setFooter("Requested by "+msg.author.tag, msg.author.avatarURL)
- return msg.channel.send(Embed)
- }
- }
- timestamps.set(msg.author.id, now)
- setTimeout(() => timestamps.delete(msg.author.id), cooldownAmount)
- // Enabled Check
- if (command.module && Bot.Config[msg.guild.id] && msg.channel.type == "text" && command.guildOnly) {
- if (!Bot.Config[msg.guild.id].modules[command.module][commandName].enabled) return
- }
- // Permission check
- if (command.permissions && Bot.Config[msg.guild.id] && msg.channel.type == "text"){
- if (!msg.member.hasPermission(command.permissions)){
- const Embed = new Bot.Discord.RichEmbed()
- .setColor("#ff0000")
- .setTitle("You do not have permission to run `"+commandName+"`!")
- .setFooter("Requested by "+msg.author.tag, msg.author.avatarURL)
- return msg.channel.send(Embed)
- }
- if (!msg.guild.me.hasPermission(command.permissions)){
- const Embed = new Bot.Discord.RichEmbed()
- .setColor("#ff0000")
- .setTitle("I do not have permission to run `"+commandName+"`!")
- .setFooter("Requested by "+msg.author.tag, msg.author.avatarURL)
- return msg.channel.send(Embed)
- }
- }
- // Argument check
- if (command.args && !args.length) {
- const Embed = new Bot.Discord.RichEmbed()
- .setColor("#ff0000")
- .setTitle("`"+commandName+"` requires arguments!")
- .setDescription("The proper usage is `"+Bot.Config[msg.guild.id].prefix+commandName+" "+command.usage+"`")
- .setFooter("Requested by "+msg.author.tag, msg.author.avatarURL)
- return msg.channel.send(Embed)
- }
- try {
- msg.react("👀")
- Bot.Commands.get(command.name).execute(Bot,msg,args)
- } catch (error) {
- msg.channel.stopTyping(true)
- const Embed = new Bot.Discord.RichEmbed()
- .setColor("#ff0000")
- .setTitle("There was an issue with running `"+commandName+"`")
- .setDescription("For geeks: `"+error+"`")
- .setFooter("Requested by "+msg.author.tag, msg.author.avatarURL)
- msg.channel.send(Embed)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement