tmijs / tmi.js

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

📝 Chat messages error handling #365

Closed dkonopka closed 4 years ago

dkonopka commented 4 years ago

Actual behaviour: No info about messages on error (timeout/banned/not conected etc).

Expected behaviour: Some err on action().

As I can see in code, this functionality is not implemented, but it would be so useful to get the possible reason why chatbot didn't make a proper message action.

 // At this time, there is no possible way to detect if a message has been sent has been eaten
 // by the server, so we can only resolve the Promise.
   resolve([channel, message]);
AlcaDesign commented 4 years ago

As the comment describes, it's not actually possible to know for sure. You can listen to "notice" events for some events that might help you understand what's going wrong.

dkonopka commented 4 years ago

Out of curiosity: it will be possible in V2?

dkonopka commented 4 years ago

Anyway, how to listen to notice events?

client.on( 'NOTICE', data => {
    console.log( data );
} );

is not working at all, when, I didn't see any docs here unfortunately :(

AlcaDesign commented 4 years ago

The event is literally notice. The msgid parameter will distinguish the value of the notice message.

client.on('notice', (channel, msgid, message) => {
});

See the Twitch docs: https://dev.twitch.tv/docs/irc/msg-id

dkonopka commented 4 years ago

Thanks for the info, but I've tried a notice too, but still no answer from this event listener :( It's interesting because:

client.on( 'message', ( channel, tags, message ) => {
    console.log( message );
} );

works properly 🤔

dkonopka commented 4 years ago

@AlcaDesign are you sure that client.on( 'notice', ( channel, msgid, message ) => { ... } ) works properly?

EightyNine commented 4 years ago

https://github.com/tmijs/docs/blob/gh-pages/_posts/v1.4.2/2019-03-03-Events.md#notice

it's possible to work with the raw data when you mean it's not working.

client.on("raw_message", (messageCloned, message) => {
    var raw = JSON.stringify(message.raw);
    var tags = JSON.stringify(message.tags); //has 'notice' and more
    var prefix = JSON.stringify(message.prefix);
    var command = JSON.stringify(message.command);
    var params = JSON.stringify(message.params);
});
dkonopka commented 4 years ago

Thank you @EightyNine for so detailed answer, I guess its worth to add this code snippet to the readme of tmi.js.