Get New Subscriber Notification or Total Sub Count using Websockets?

Hello! I am working on an Arduino based LED display that connects to Twitch chat using Websockets. My software skills are very poor, but based off some example code I am at the point where I can read messages or commands from chat and create effects on my LED array.

I would like to be able to either get notification on a new subscriber (or multiple), or I can just continuously check the total subscriber count and monitor if the number changes.

The Twitch Developer documentation was a bit hard to decipher for me. Can somebody please show me how to pull subscriber count or new subscriber notification using Websockets?

I have included the code that connects me to the channel for reference:

void webSocketEvent(WStype_t type, uint8_t * payload, size_t length) {
  switch(type) {
    // If the websocket connection is succesful, try to join the IRC server
    case WStype_CONNECTED:
      Serial.printf("[WSc] Connected to: %s\n", payload);
      webSocket.sendTXT("PASS " + String(twitch_oauth_token) + "\r\n");
      webSocket.sendTXT("NICK " + String(twitch_nick) + "\r\n");
      webSocket.sendTXT("JOIN " + String(twitch_channel) + "\r\n");
      webSocket.sendTXT("CAP REQ " + String(twitch_cap) + "\r\n");  //Tag request


You cannot get the total by a WebSocket but you can get new chat subscriber events as they occur.


This looks like you are connecting to chat and this looks correct. You will need to preceend the channel name with a ‘#’ and needs it a;; to be lowser case. In theory you could use the anon login. saves juggily tokens.

Then just parse for messages of type USERSTATE instead of PRIVMSG then you’ll get (re)subscriptions shared in chat.

You cannot get the total subs from a WebSocket, you’ll need to poll the API for the current count. Reference | Twitch Developers which will need the token

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.