I have been messing around with this spam check bot, and i would love to do it so it warns you after first 5 spam messages, and mutes you after 15. I tried to use else if command, but that didnt success that well :D
What should i do?
code:
function spamCheck(msg, set, time) {
if (msg.member.roles.cache.find(role => role.name === 'Muted')) return
let bool = false
let user = { id: msg.author.id, time: Date.now(), times: 1 }
for(let u of set) {
if (isNaN(u.times)) u.times = 1
if (u.id === msg.author.id) {
bool = true
if(u.times == 5) {
msg.reply(`Please Do not spam!`)
let muterole = msg.guild.roles.cache.find(role => role.name === 'Muted')
if(!msg.member.roles.cache.has(muterole.id)) {
msg.member.roles.add(muterole)
setTimeout(() => {
msg.member.roles.remove(muterole)
set.delete(u)
msg.channel.send('**Unmuted**')
}, 5000);
}
} else if ((Date.now() - u.time) <= time) {
u.times++
u.time = Date.now()
}
}
}
if (bool === false) {
set.add(user)
}
}
module.exports = { spamCheck }```