# Get New Subscriber Notification or Total Sub Count using Websockets?

**URL:** <https://discuss.dev.twitch.com/t/get-new-subscriber-notification-or-total-sub-count-using-websockets/33247>\
**Category:** API\
**Created:** [August 26, 2021, 9:18am UTC](https://discuss.dev.twitch.com/t/get-new-subscriber-notification-or-total-sub-count-using-websockets/33247 "2021-08-26T09:18:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![drslump](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/drslump/32/12099_2.png) [@drslump](https://discuss.dev.twitch.com/u/drslump)\
**Post date:** [August 26, 2021, 9:18am UTC](https://discuss.dev.twitch.com/t/get-new-subscriber-notification-or-total-sub-count-using-websockets/33247/1 "2021-08-26T09:18:28Z")

</div>

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:

```auto

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:
      digitalWrite(onbLED,HIGH);
      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

      break;

```

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [August 26, 2021, 9:23am UTC](https://discuss.dev.twitch.com/t/get-new-subscriber-notification-or-total-sub-count-using-websockets/33247/2 "2021-08-26T09:23:54Z")

</div>

> [@drslump](#):
>
> 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?

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

Either

- connect to chat and consume the events - [Twitch IRC Tags | Twitch Developers](https://dev.twitch.tv/docs/irc/tags#usernotice-twitch-tags) - an example [https://github.com/BarryCarlyon/twitch\_misc/tree/main/chat](https://github.com/BarryCarlyon/twitch_misc/tree/main/chat)
- connect to pubsub and consume the events - [PubSub | Twitch Developers](https://dev.twitch.tv/docs/pubsub) - an example [https://github.com/BarryCarlyon/twitch\_misc/tree/main/pubsub](https://github.com/BarryCarlyon/twitch_misc/tree/main/pubsub)
- wait for EventSub to have WebSocket Support and consume the events. - [RFC 0016 - EventSub WebSockets - #7 by BarryCarlyon](https://discuss.dev.twitch.com/t/rfc-0016-eventsub-websockets/32652/7)

> [@drslump](#):
>
> I have included the code that connects me to the channel for reference:

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](https://dev.twitch.tv/docs/api/reference#get-broadcaster-subscriptions) which will need the token

---

<div class="post-metadata">

**Author:** ![system](https://d2opxh93rbxzdn.cloudfront.net/original/2X/0/05909729875cce3b53e59d5561c4d23bb14948fc.png) [@system](https://discuss.dev.twitch.com/u/system)\
**Post date:** [September 25, 2021, 9:24am UTC](https://discuss.dev.twitch.com/t/get-new-subscriber-notification-or-total-sub-count-using-websockets/33247/3 "2021-09-25T09:24:37Z")

</div>

Closed on September 25, 2021, 9:24am UTC

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