Im trying to make a boost command where the whole server can only boost once every 10 seconds (for testing).
The code:
const timeout = 10000 //3600000
Boost.findOne({
guildID: bot.guilds.cache.get(message.guild.id).id
}, (err, data) => {
if (err) console.log(err)
if (!data) {
const newData = new Boost({
guildID: bot.guilds.cache.get(message.guild.id).id,
guildName: bot.guilds.cache.get(message.guild.id).name,
boostAmount: 1,
cooldown: Date.now()
})
newData.save().catch(err => console.log(err));
let embed = new MessageEmbed()
.setTitle(`${bot.guilds.cache.get(message.guild.id).name} was boosted!`)
.setColor("#f48771")
.setDescription(`**Amount of boosts: 1**`)
.addField(`Boost again in`, `**0h 0m 10s**`)
return message.channel.send(embed)
} else {
if (timeout - (Date.now() - data.cooldown) > 0) {
let time = ms(timeout - (Date.now() - data.cooldown))
let timeoutEmbed = new MessageEmbed()
.setTitle("Wait a little bit more.")
.setColor("#f48771")
.setDescription(`**Someone already boosted your server in the last day.**`)
.addField(`Boost again in`, `**${time.hours}h ${time.minutes}m ${time.seconds}s**`)
return message.channel.send(timeoutEmbed);
} else {
data.boostAmount += 1
data.save().catch(err => console.log(err))
let boostAmountEmbed = new MessageEmbed()
.setTitle(`${bot.guilds.cache.get(message.guild.id).name} was boosted!`)
.setColor("#f48771")
.setDescription(`**Amount of boosts: ${data.boostAmount}**`)
.addField(`Boost again in`, `**0h 0m 10s**`)
return message.channel.send(boostAmountEmbed)
}
}
})
The problem im getting here is that when the new data is created in the mongodb it ups the boost by one and then if I do the boost command again, it says the proper timeout embed but then when I wait one more time, the timeout doesn’t go through and they can do the boost command unlimited times.
Screenshots:
and then so on and I can boost it an unlimited amount of times.