Track new bit cheering event - With C# (Unity)

Hello all!

I am posting here, because I need help with tracking new Bits cheering events on a twitch channel inside my Unity C# application. So far, I have a communication with the Twitch Client and Twitch API, letting me receive information via multiple OnEvent methods (such as client.OnNewSubscriber) and GetChattersAsync via the API.

Question 1:
From what I found out, I am supposed to use the API.Helix methods, but I am unsure which is the correct method to track NEW occuring events. I only see leaderboards and such.

Question 2:
I have difficulties understanding the Invoke process when using the Twitch API. I saw mostly posts talking about sending a request to an URL via http and add information in headers. Honestly, I am not well versed in this category, so I was relying on the API.Invoke method, but aside from GetChattersAsync I cannot make anything else work.

Here is the working example:

Invoke step:
api.Invoke(api.Undocumented.GetChattersAsync(ourTwitchClient.client.JoinedChannels[0].Channel), GetChatterListCallback);

Feedback method:
private void GetChatterListCallback(List listOfChatters)
Debug.Log("List of " + listOfChatters.Count + " Viewers: ");
foreach (var chatterObject in listOfChatters)

Here is a NOT working example of GetBitsLeaderboardAsync:

Invoke step:
api.Invoke(api.Helix.Bits.GetBitsLeaderboardAsync(), GetBitsLeaderboard);

Feedback method:
private void GetBitsLeaderboard(GetBitsLeaderboardResponse bitsLeaderboardResponse)
Debug.Log("Leaderboard documented: " + bitsLeaderboardResponse.ToString());

If relevant, here is my API setup code:
api = new Api();
api.Settings.AccessToken = Secrets.BOT_ACCESS_TOKEN;
api.Settings.ClientId = Secrets.CLIENT_ID;

So basically, as summary again, I want to react on a new bits cheer event inside my Unity project.

Thank you very much for your help in advance! I am posting this, because I really am stuck for days now on this.

Best regards.

Live bits events are provided either

Well it’s undocumented so it doesn’t need speicific headers and can change or break at any time.

Helix (and kraken/old API) don’t provide a bits/events endpoints, it’s all Chat/PubSub and now EventSub.

This depends on the HTTP library you are using.
It should provide documentation on how to add headers or tell it you are using oAuth.

You’ll also need to setup a simple webpage or callback system to obtain a suitably scoped oAuth access token for your account in order to read the bits data

Pick which one of the three methods you want to use and work out from there. For Unity you probably want Chat or PubSub since you are not on a web accessable server and eventsub doesn’t have a socket transport yet

1 Like

Thank you for your quic response, Barry! I really appreciate it.

Right now I am trying the privmsg way, because its the easiest way and corresponds with the code I already have. It looks roughly like this and lets me track all the messages from chat:

twitchClient = new TcpClient(“”, 6667);
reader = new StreamReader(twitchClient.GetStream());
writer = new StreamWriter(twitchClient.GetStream());

if(twitchClient.Available > 0) string message = reader.ReadLine();

In this state, message give me text like this: ":thepersonwhocheered! PRIVMSG #thechannelicheeredon :Cheer1 Testest

For clarification, “thepersonwhocheered” is my ‘censored’ username that gives the bit, while “thechannelicheeredon” is the ‘censored’ channel that received the bit. Bascially, I can work with that, but I have two doubts:

First doubt:
In the first link you send ( there is the bits tag mentioned related to privmsg. But I did not see that tag when I tested with real bit cheers. Do I have to “look for” bits events specifically by changing this line here? ->
twitchClient = new TcpClient(“”, 6667);

Second doubt:
That leads me to my second doubt. With that setup, I basically only see the same thing as if I would track the chat contents. The problem with that is that cheers can have a different format than e.g. “cheer100”. It could also be PogChamp100 or Kappa100. It would not be efficient and reliable to filter all of these possibilities out.

So basiacally as summary, can I extract a similar message to my example above that ONLY reacts to bits and always gives me the bits amount and who gave the bits, even when CheerMotes are being used? If yes, what would I have to change?

Then you didn’t send the TAGS (or COMMANDS) CAPability requests

Then you just read for the bits tag being present. Not bits tag it’s not a bits message.

If you don’t need the individual cheer motes used, just request and then parse the tags for the bits tag being present or not.

The tags guide I linked to provides a sample regex to use if you need the individual cheer motes used

Holy ****, it worked! Thanks so much Barry! The CAP thing was the missing link.

For others, here is what I added to my code (in bold):

twitchClient = new TcpClient(“”, 6667);
reader = new StreamReader(twitchClient.GetStream());
writer = new StreamWriter(twitchClient.GetStream());

writer.WriteLine("PASS " + password);
writer.WriteLine("NICK " + username);
writer.WriteLine(“USER " + username + " 8 * :” + username);
writer.WriteLine(“JOIN #” + channelName);
writer.WriteLine(“CAP REQ”);

Now I get a huge message that looks like this, but it has all the infos I need:
"@badge-info=subscriber/4;badges=moderator/1,subscriber/3,bits/1;bits=1;color=;display-name=TwitchUser1234;emotes=;flags=;id=da6ec4c6-af61-4346-abc-123456789;mod=1;room-id=12345678;subscriber=1;tmi-sent-ts=160987654321;turbo=0;user-id=123456789;user-type=mod PRIVMSG #thechannelyouarewatching :PogChamp1 Another Test Bit"

Have a great day everyone!

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