tmijs / tmi.js

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

Not connected to server #293

Closed Rhyzox closed 5 years ago

Rhyzox commented 6 years ago

switch(message.toLowerCase()){ case${prefix}help: client._sendMessage(0, channel, "Help: "); break; }

I got the error:

(node:7124) UnhandledPromiseRejectionWarning: Not connected to server. (node:7124) UnhandledPromiseRejectionWarning: Unhandled promise rejection. 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(). (rejection id: 1) (node:7124) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

AlcaDesign commented 6 years ago

There's not enough of your code to tell you exactly what's happening, but you shouldn't use "._sendMessage" as this is an internal method used by the more appropriate ".say" method.

Zelak312 commented 6 years ago

Not sure why but I get the same Not connected to server issue even with the .say function here is my code

const client = new tmi.client(options);

client.connect();

client.on("chat", (chan, user, message, self) => {
    client.say(chan, "pong");
});

I also have the debug on true to see and it says that it connects successfully to the server. Here is the log

[12:34] info: Connecting to irc-ws.chat.twitch.tv on port 80..
[12:34] info: Sending authentication to server..
[12:34] info: Connected to server.
[12:34] info: Joined #zelak312
[12:34] info: [#zelak312] <zelak312>: m!ping
Not connected to server. Promise { <rejected> 'Not connected to server.' }
AlcaDesign commented 6 years ago

@ZelAk312 I think you might be spamming the server and getting forcefully disconnected by Twitch. You have an unintended loop:

When the bot sends a message called via the say & action methods, it will emit another "chat" event.

https://github.com/tmijs/tmi.js/blob/4dcfa551c4616d584f3d2e3d6e147bfa3f5256ba/lib/client.js#L1101-L1118

This is where the self boolean value passed in the event is useful.

client.on("chat", (chan, user, message, self) => {
    if(self) {
        return;
    }
    client.say(chan, "pong");
});
Zelak312 commented 6 years ago

I found out my problem I had a typo in the "identity" property