Hello! I wrote the code, but I’m not sure if I wrote it correctly. I have to connect to the chat and immediately send a message.
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');
connection.sendUTF('PASS oauth:vz9fcq1xv0qxxr7kcr2g9btubgdofayyzq2r142p7kygtqx12zde4ugpdx83tt1qr35u6jqlcbbn4ix526rgsfxiypq130z2kbqflvxyxf5jnl4j7ued2nyt17b9iayzcg959kxw2cp69q4e3mzkfmfwhtmy46601oy46z6uf6qus2y5qq9egoo1c8f7qvpwreen0gfdnb57o6xscqpdddfyfe62oykiniiu7zatq44imae3rjxr2un04r1ut2jd6j3tnt2oao19l7ro43j12nn1h1rmc71tvtxtm7qm324zbvpwn6g3i1rxyfnw4f0pero884hedm3ilxe6qa47lcb7ou01m47g4oknw1gizt9vwh7m8cowi5jdalf5t87vpb5e9v5kpw170iimnykjf8x4ao0icrf5y4dv');
connection.sendUTF('NICK S4tont');
});
connection.on('message', function(ircMessage) {
client.send('JOIN #s4tont');
client.send('PRIVMSG #s4tont :hello!');
});
client.connect('ws://irc-ws.chat.twitch.tv:80');
Error:
/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