Member Avatar for Member #954384

So I currently have a bot in mIRC, but I want to develop a bot in C#. I am trying to figure out how to parse JSON in C#. My goal is to get recent followers and check for followers(this is where json comes in) and add a points system.

My goal is to eventually develop a program with a GUI but for now it is in console format. Can someone point me in the right direction, or possible give me some code examples on how I would go about doing this? Any help with this would be much appreciated as I am very new to C#.

Thanks,
Zac

Dani AI

Generated

A practical, low-friction path from a mIRC bot to a C# Twitch bot: pick a JSON library (modern .NET includes System.Text.Json; Newtonsoft.Json is still common — see and ), register an app on the Twitch developer console, get an access token, then either poll the Helix follower endpoint or subscribe to EventSub for real‑time follow events. EventSub avoids constant polling and is the recommended way to get immediate follower notifications; the Helix "Get Channel Followers" endpoint can be used for ad‑hoc checks but returns detailed follower objects only when the token has the right moderator/broadcaster scope. (dev.twitch.tv)

Minimal workflow to implement:

  • Register the app and obtain client_id + client_secret, then get an app or user access token (client credentials or authorization code/device flow depending on needs).
  • For real‑time: create an EventSub subscription for channel.follow (webhook or websocket transport).
  • For polling: call GET https://api.twitch.tv/helix/channels/followers?broadcaster_id={id}&first=100 and page using the returned cursor; persist the latest follower id/timestamp to avoid double‑awarding points. (dev.twitch.tv)

Example (console) — HTTP GET + System.Text.Json parsing:

using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text.Json;
using System.Threading.Tasks;

static readonly HttpClient http = new HttpClient();

static async Task GetFollowers(string clientId, string token, string broadcasterId)
{
    var url = $"https://api.twitch.tv/helix/channels/followers?broadcaster_id={broadcasterId}&first=100";
    var req = new HttpRequestMessage(HttpMethod.Get, url);
    req.Headers.Add("Client-Id", clientId);
    req.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);

    using var resp = await http.SendAsync(req);
    resp.EnsureSuccessStatusCode();

    using var doc = JsonDocument.Parse(await resp.Content.ReadAsStringAsync());
    foreach (var item in doc.RootElement.GetProperty("data").EnumerateArray())
    {
        var login = item.GetProperty("user_login").GetString();
        var name = item.GetProperty("user_name").GetString();
        var when = item.GetProperty("followed_at").GetString();
        Console.WriteLine($"{name} ({login}) followed at {when}");
    }
}

Keep a long‑lived HttpClient (or use IHttpClientFactory) to avoid socket exhaustion, and honor Twitch rate limits — EventSub reduces request load compared with polling. For a GUI/points system, store follower IDs/timestamps in a small local DB (SQLite) and update an in‑memory collection (ObservableCollection or DataTable) for binding; that makes awarding points and showing history deterministic. (learn.microsoft.com)

Recommended Answers

All 2 Replies

I can personally recomment the library pritaeas suggested. I just recently used that library in a project for a client. It works VERY good (And has the ability to return results in a DataSet, allowing for dynamic JSON work).

Oh yes and it has an MIT License which is always nice

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.