const cmd = client.commands.get(command) || client.commands.find(a => a.aliases && a.aliases.includes(command)) if(cmd) { const CD = require('./Schemas/CooldownSchema') const cd = CD.findOne({Guild: message.guild.id, CommandName: cmd.name, UsedBy: message.author.id}); if(!cd || cd && Math.ceil((cd.Used + (cd.Cooldown * 1000) - Date.now())) <= 0) { if(cd) cd.deleteOne().catch(err => console.log(err)); if(cmd) cmd.execute(client, message, args) const cooldown = new CD({ Guild: message.guild.id, CommandName: cmd.name, Used: Date.now(), UsedBy: message.author.id, Cooldown: cmd.cooldown, }) cooldown.save().catch(err => console.log(err)); setTimeout(async () => { if(cd) cooldown.deleteOne().catch(err => console.log(err)); }, cmd.cooldown * 1000) } else if(cd && Math.ceil((cd.Used + (cd.Cooldown * 1000) - Date.now())) >= 1) { return message.reply(`You need to wait **${Math.ceil((cd.Used + (cd.Cooldown * 1000) - Date.now()) / 1000)}** seconds before using this command again!`).then(message.delete(2000)) } }