if (cmd) { if (cmd.cooldown) { const cd = require('./Schema/cooldown'); cd.findOne({ guildID: message.guild.id, userID: message.author.id, command: cmd.name }, async (err, data) => { const cds = await cd.findOne({ guildID: message.guild.id, userID: message.author.id, command: cmd.name }) if (data) { let timeLeft = ms(cds.time - Date.now(), { long: true }); message.channel.send(`Command is on cooldown. You need to wait ${timeLeft}`) return } else { if (cmd) cmd.execute(client, message, args, prefix) if (cmd.cooldown === 0) { new cd({ userID: message.author.id, time: cmd.cooldown + Date.now(), command: cmd.name }).save() } else { new cd({ userID: message.author.id, time: cmd.cooldown + Date.now(), command: cmd.name }).save() } setTimeout(async () => { const data = await cd.findOne({ guildID: message.guild.id, userID: message.author.id, command: cmd.name }); if (data) data.delete() }, cmd.cooldown) } }) } }