0

I want my bot to give coins to members that spent 1 minute in any voice channel. When I'm sitting in voice channel it's working good, but if I am quitting a channel, the bot still gives me 1 coin per minute. What did I do wrong?

I tried to stop a function when the user leaves a channel, tried to clear a timeout function, but it's still working that way:

bot.on("voiceStateUpdate",(oldMember,newMember)=>{
    let nuc = newMember.voiceChannel
    if(nuc !== undefined){ 
        function smth() {
            setTimeout(function coin() {
            db.add(`money_${newMember.id}`, 1)
            setTimeout(coin, 60000);
        }, 60000)}  
        smth()
        newMember.send('You're in voicechannel')
    } else {
        return newMember.send('You're out of voicechannel')
    }
})
rohrl77
  • 3,277
  • 11
  • 47
  • 73
tori
  • 1
  • 1

0 Answers0