tmijs / tmi.js

💬 Javascript library for the Twitch Messaging Interface. (Twitch.tv)
https://tmijs.com
MIT License
1.56k stars 212 forks source link

Disconect after client.say #127

Closed ImChiip closed 8 years ago

ImChiip commented 8 years ago

Actual behaviour: Hello I'm about to write a bot twitch I encounter a problem with tmi.js The bot disconnects as soon as a message is sent with client.say log level the message is sent but not on the cat twitch

log:

[12:08pm] info: Connecting to irc-ws.chat.twitch.tv on port 80..
[12:08pm] info: Sending authentication to server..
[12:08pm] info: Connected to server.
[12:08pm] info: Joined #MyRoom
[12:08pm] info: [#MyRoom] <My Name>: test
[12:08pm] info: [#MyRoom] <imb0t>: This is a test message
[12:08pm] error: Could not connect to server. Trying to reconnect in 0 seconds..
[12:08pm] info: Connecting to irc-ws.chat.twitch.tv on port 80..
[12:08pm] info: Sending authentication to server..
[12:08pm] info: Connected to server.
[12:08pm] info: Joined #MyRoom

Server configuration

PS: im french sorry for my bad english :)

AlcaDesign commented 8 years ago

Can you describe or share what triggers the bot's response?

ImChiip commented 8 years ago

@AlcaDesign I do not understand very well But here's the code I call in my function

client.on("chat", function (channel, user, message, self) {
    if (user["user-type"] === "mod" || user.username === channel.replace("#", "")) {
        client.say("#MyRoom", "My Message");
    }
});
AlcaDesign commented 8 years ago

A fatal mistake by users when initially testing the module is allowing the bot to respond to itself. The self argument tells the event listener that the call came from the same tmi.js client. I don't know if this will solve your problem, but I will suggest that you do this in your function:

client.on("chat", function (channel, user, message, self) {
    if(self) return false;
    // ...
})
ImChiip commented 8 years ago

@AlcaDesign Thank you for the help I did not use the script from 1h and his works There have anti flood protection on twitch?

Thank you for all this I will use the method that give you :)

AlcaDesign commented 8 years ago

If you listen to the "notice" event and console.log it, you might get "You're sending messages to quickly" ... this is Twitch telling you to slow down. The tmi.js library doesn't come with food protection, but you could probably find a queuing library on npm.

AlcaDesign commented 8 years ago

Here's a link to the "notice" event in the docs