Search code examples
javascriptchatbottwitch

How do I timeout someone with a twitch bot (client.timeout and client.say(channel, `/timeout @${tags.username} dont work)?


I can't ban or timeout users with a Twitch chatbot who write certain words in js. However, I can send messages with the bot.

My code:

client.on('message', async (channel, tags, message, self) => {
    if (self) return;

    console.log(`${tags['display-name']}: ${message}`);
    console.log(tags.username)



    const forbiddenWords = ['test1', 'test2', 'test3'];
    for (let i = 0, len = forbiddenWords.length; i < len; i++) {
        if(forbiddenWords[i] == message){
            const timeoutReason = `Explicit language: ${message}`;
            client.timeout(channel, tags.username, 10, timeoutReason);
            client.say(channel, `You got timeout for using explicit language! @${tags.username}`);
            console.log(`${tags.username} has been timeouted for: "${message}"!`);
          }
      }
});

I recently tried to create a Twitch ChatBot and ran into a problem with bans and timeouts. I created an oauth token on https://twitchapps.com/tmi/ but am having either permission issues or the two methods:

const timeoutReason = `Explicit language: ${message}`;
client.timeout(channel, tags.username, 1`your text`0, timeoutReason);
and:
/client.say(channel, `/timeout @${tags.username} 10
do not work anymore.

EEither the person who should be banned is not blocked or I get this error:
node:internal/process/promises:289
            triggerUncaughtException(err, true /* fromPromise */);
            ^

[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "No response from Twitch.".] {
  code: 'ERR_UNHANDLED_REJECTION'
}

Solution

  • Twitch moved the commands to the API, the only command you can cast with tmi.js is /me.

    https://discuss.dev.twitch.com/t/deprecation-of-chat-commands-through-irc/40486