This websockets implementation can be used to listen to the chatroom on the side of livestreams, and even interact with it.


const chat = {
    channels: [],
    extensions: {},
    address: 'wss://',
    timeout: 7000

const twitch = new Twitch('your-oauth-token', { chat });
parameter description
channels Array of channels you want to join (Default: [])
extensions Object of extensions you want to use (Default: {})
address Websocket address (Default: wss://
timeout Timeout for connection join, etc. (Default: 7000)

Connect join part and disconnect

If you are connected already the connect method will disconnect then reconnect. When connecting to chat the channels you set on instantiation are joined automatically however you may also dynamically join and part from channels if you choose.

// chat is now connected

// #channel is now joined

// #channel is now parted

// chat is now disconnected


While connected to chat, every line is parsed into an object and then emitted via node EventEmitter on the chat instance. Event names are the Twitch command, otherwise UNKNOWN. In addition all messages emit the message event.

There are also connection status events.'message', function (msg) {
    // msg received from chat
event description
disconnected Chat has disconnected
connecting Chat is connecting
connected Chat is connected
authenticated Chat has successfully authenticated
ready The above and chat has re-joined channels
message Message
error An error has occurred

Examples of listening to and making use of chat events can be found on the examples page.


To write a message safely into chat use the send method. The first parameter is what you want to write, the second parameter is the minimum connection status it needs to wait for (Default: 'ready').

Useful in case the chat is reconnecting.'PRIVMSG #channel :Hello everyone!');

Send unsafe

To write a message directly into chat without any protection use the sendUnsafe method.'PRIVMSG #channel :No idea if this message will show up');


A convenience method for writing a message into chat, is the same as using the example from send above.'#channel', 'Hello everyone!');