DEV Community

loading...

Twitch IRC Capability WebSocket (help)

zaekof profile image NOGIER Loïc Updated on ・1 min read

I'am trying to get a event when a moderator unban a user in the chat, i send a resquest for twitch.tv/tags but i didn't receive any messages when user was ban or unban...

it is my actual code :

const WebSocket = require('ws');

const ws = new WebSocket('wss://irc-ws.chat.twitch.tv:443');

ws.onopen = function(event) {
  console.log('INFO: Socket Opened'); 
  ws.send('CAP REQ :twitch.tv/commands');
  ws.send('CAP REQ :twitch.tv/membership');
  ws.send('CAP REQ :twitch.tv/tags');
  ws.send('PASS oauth:...');
  ws.send('NICK zaekof_');
  ws.send('JOIN #zaekof_');
  ws.send('USER #zaekof_');
};
ws.onerror = function(error) {
  console.log('ERR: ', error);
};
ws.onclose = function() {
  console.log('INFO: Socket Closed');
}; 
ws.onmessage = function(event) {
  console.log('RECV: ', event.data);
};
Enter fullscreen mode Exit fullscreen mode

When i'am connected on irc chat, i receive a follows messages :

RECV:  :tmi.twitch.tv CAP * ACK :twitch.tv/commands
RECV:  :tmi.twitch.tv CAP * ACK :twitch.tv/membership
RECV:  :tmi.twitch.tv CAP * ACK :twitch.tv/tags

RECV:  :tmi.twitch.tv 001 zaekof_ :Welcome, GLHF!
:tmi.twitch.tv 002 zaekof_ :Your host is tmi.twitch.tv
:tmi.twitch.tv 003 zaekof_ :This server is rather new
:tmi.twitch.tv 004 zaekof_ :-
:tmi.twitch.tv 375 zaekof_ :-
:tmi.twitch.tv 372 zaekof_ :You are in a maze of twisty passages, all alike.:tmi.twitch.tv 376 zaekof_ :>
Enter fullscreen mode Exit fullscreen mode

Would anyone have an idea to help me?

Thanks.

Discussion (4)

Collapse
f3ltron profile image
florent giraud

did you consider using that lib ? docs.tmijs.org/v1.4.2/Events.html

It will facilitate you the job :)

Collapse
zaekof profile image
NOGIER Loïc Author

Thanks for reply, i go look :)

Collapse
zaekof profile image
NOGIER Loïc Author

It is a right way to do what i want ?

const tmi = require("tmi.js");

let options = {
  options: {
    debug: true,
    clientId: '...'
  },
  connection: {
    server: 'irc-ws.chat.twitch.tv',
    reconnect: true,
    secure: true
  },
  identity: {
    username: "zaekof_",
    password: "oauth:..."
  },
  channels: [ "#zaekof_" ]
};

let client = new tmi.client(options);

client.on("notice", (channel, msgid, message) => {
  console.log(msgid, message);
});

client.connect();

I didn't have any return when i use /unban in chat, just :

[16:34] info: [#zaekof_] ... has been banned.

I'm confused, I must have missed something ^

Thread Thread
f3ltron profile image
florent giraud

you have to put the ids from the bot or you depend and ban from this user you or the bot because it will listen commands from the ids you enter client secret or id

Forem Open with the Forem app