Twitch TMI Command Timeout

Hi All,

Im working on a Twitch Bot and currently when someone types a command it will reply back. But if someone spams the command it also spams it back. I want to set a cooldown so that when someone uses the Command “!play” it waits 1 min before looking to see if someone has sent it again.


client.connect();

  client.on('message', (channel, tags, message, self) => {

    if(self) return;

    if(message.toLowerCase() === '!play') {

      console.log(client.say(channel, `!play`));

    }

});

Basica javascript example that would suffice

var block = false;

client.connect();

  client.on('message', (channel, tags, message, self) => {

    if(self) return;

    if(message.toLowerCase() === '!play') {
      if (!block) {
          console.log(client.say(channel, `!play`));
          block = true;
          setTimeout(() => {
              block = false;
          }, (60 * 1000));
      }
    }

});
1 Like