Timeout with tmi.js

Hello I’ve got a question about the timeout feature

I read their doc about the timeout feature but I don’t really understand since there are 2 read.md, one called as event.md docs/2019-03-03-Events.md at gh-pages · tmijs/docs · GitHub and the other one as a command.md docs/2019-03-03-Commands.md at gh-pages · tmijs/docs · GitHub

I only understood a bit how it works but not properly because what I would like to do in my code is to timeout a user after they posted a keyword (like an inappropriate word in their message) and I don’t know which one to use. Thanks !

Events - something happened and we saw it
Commands - a thing the bot can do

To put it another way

Commands - the bot times out a user
Events - someone (even the bot) timed out a user and we are seeing that it occured.

So you want whats in Commands.md

so for example I could use conditions or switch like if there is such word such word on chat etc…
client.timeout(mychannel, “username”, a duration, “reason”); ?

Sure you can make your bot do anything in response to a message.

When you get a message, read the message, see if that messages breaks your rules and then issue a timeout as you have written. Using a Command.

Sorry to bother you again, for example I tried
client.on(‘chat’, (channel, user, message, userstate, self) => {
if (message == ‘tm’) (just to test ofc) {
client.timeout(mychannel, userstate[“target-user-id”], userstate[“room-id”], a duration, “reason”);
}
}); didn’t work

or client.on(‘chat’, (channel, user, message, self) => {
if (message == ‘tm’) {
client.timeout(mychannel, “username”, a duration, “reason”);
}
}); and also didn’t work

What should I type with timeout shit with conditions ?

If it didn’t work then it should of returned and error.

You are not logging the error

As per the example in the docs

client.timeout("channel", "username", 300, "reason")
.then((data) => {
    // data returns [channel, username, seconds, reason]
}).catch((err) => {
    //
});

You can add logging inside the catch and/or do whatever additional things in the catch you need

Works now, thank you very much I used tags.username instead of the userstate param

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.