I connect to Twitch Chat via a socket, using an IRC style interface.
My code:
const WebSocketClient = require('websocket').client;
const client = new WebSocketClient();
client.on('connectFailed', function(error) {
console.log('Connect Error: ' + error.toString());
});
client.on('connect', function(connection) {
console.log('WebSocket Client Connected');
// Send CAP (optional), PASS, and NICK messages
});
client.connect('ws://irc-ws.chat.twitch.tv:80');
But how to send a message immediately after connecting? And how do you choose which channel to connect to?
I just don’t know how to connect to the chat
/home/user/Documents/typescript/bots/twitch/twitch.js:42
connection.on('message', function(ircMessage) {
^
ReferenceError: connection is not defined
at Object.<anonymous> (/home/user/Documents/typescript/bots/twitch/twitch.js:42:1)
at Module._compile (node:internal/modules/cjs/loader:1126:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
at Module.load (node:internal/modules/cjs/loader:1004:32)
at Function.Module._load (node:internal/modules/cjs/loader:839:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:17:47