# Check if channel is live \[C#, Discord\]

**URL:** <https://discuss.dev.twitch.com/t/check-if-channel-is-live-c-discord/14958>\
**Category:** API\
**Created:** [March 28, 2018, 9:57pm UTC](https://discuss.dev.twitch.com/t/check-if-channel-is-live-c-discord/14958 "2018-03-28T21:57:18Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lightstreak](https://avatars.discourse-cdn.com/v4/letter/l/49beb7/32.png) [@Lightstreak](https://discuss.dev.twitch.com/u/Lightstreak)\
**Post date:** [March 28, 2018, 9:57pm UTC](https://discuss.dev.twitch.com/t/check-if-channel-is-live-c-discord/14958/1 "2018-03-28T21:57:18Z")

</div>

Hello.  
My problem is very simple: I’m trying to make my discord bot check if a channel has gone live, and I cannot figure out how to do it. I get it has something to do with Json and html and whatnot but I don’t actually know how to work with JSON or Html, and I’m “self-taught” so I fear I may not be knowledgeable enough to solve this on my own ☹  
I also want it to check the “title” of the stream which is set with Nightbot.  
I don’t even have any code yet.

---

<div class="post-metadata">

**Author:** ![out7](https://avatars.discourse-cdn.com/v4/letter/o/50afbb/32.png) [@out7](https://discuss.dev.twitch.com/u/out7)\
**Post date:** [March 28, 2018, 10:40pm UTC](https://discuss.dev.twitch.com/t/check-if-channel-is-live-c-discord/14958/2 "2018-03-28T22:40:56Z")

</div>

You need to use C# to load (GET) a web URL - [https://api.twitch.tv/helix/streams?user\_login=lightstreak](https://api.twitch.tv/helix/streams?user_login=lightstreak) Replace _lightstreak_ with the user you are interested in.  
You need to set a Header with your Client-ID.

Then, when you load the URL, you will get a response in JSON format - this is why you need to parse JSON.

If the user is not online, you will get a response like this:

> ```
> {
> "data": [],
> "pagination": {}
> }
> 
> ```

If the user is online, you will get a response like this:

> ```
> {
> "data": [
> {
> "id": "28110269104",
> "user_id": "26490481",
> "game_id": "497078",
> "community_ids": [],
> "type": "live",
> "title": "FC5 PC First Playthrough - [Follow @summit1g]",
> "viewer_count": 25871,
> "started_at": "2018-03-28T19:29:14Z",
> "language": "en",
> "thumbnail_url": "https://static-cdn.jtvnw.net/previews-ttv/live_user_summit1g-{width}x{height}.jpg"
> }
> ],
> "pagination": {
> "cursor": "eyJiIjpudWxsLCJhIjp7Ik9mZnNldCI6MX19"
> }
> }
> 
> ```

Note that type is “live”

---

<div class="post-metadata">

**Author:** ![Lightstreak](https://avatars.discourse-cdn.com/v4/letter/l/49beb7/32.png) [@Lightstreak](https://discuss.dev.twitch.com/u/Lightstreak)\
**Post date:** [March 28, 2018, 10:46pm UTC](https://discuss.dev.twitch.com/t/check-if-channel-is-live-c-discord/14958/3 "2018-03-28T22:46:17Z")

</div>

so would I do something like “if data is null , then send message streamer not online else streamer is online”.  
I have a script that handles commands. Would I put that in there?

---

<div class="post-metadata">

**Author:** ![3ventic](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/3ventic/32/298_2.png) [@3ventic](https://discuss.dev.twitch.com/u/3ventic)\
**Post date:** [March 28, 2018, 10:47pm UTC](https://discuss.dev.twitch.com/t/check-if-channel-is-live-c-discord/14958/4 "2018-03-28T22:47:37Z")

</div>

Have a look at `System.Net.HttpClient` (`GetStringAsync`, `DefaultRequestHeaders`) for making the API request and `Newtonsoft.Json` (`DeserializeObject<T>`) for parsing the response.

If the returned array contains the stream, it’s online. Otherwise it’s offline.

---

<div class="post-metadata">

**Author:** ![Lightstreak](https://avatars.discourse-cdn.com/v4/letter/l/49beb7/32.png) [@Lightstreak](https://discuss.dev.twitch.com/u/Lightstreak)\
**Post date:** [March 28, 2018, 11:15pm UTC](https://discuss.dev.twitch.com/t/check-if-channel-is-live-c-discord/14958/5 "2018-03-28T23:15:30Z")

</div>

DO I need to use some specific librairy

---

<div class="post-metadata">

**Author:** ![out7](https://avatars.discourse-cdn.com/v4/letter/o/50afbb/32.png) [@out7](https://discuss.dev.twitch.com/u/out7)\
**Post date:** [March 28, 2018, 11:34pm UTC](https://discuss.dev.twitch.com/t/check-if-channel-is-live-c-discord/14958/6 "2018-03-28T23:34:38Z")

</div>

He told you:

> [@3ventic](#):
>
> Have a look at System.Net.HttpClient (GetStringAsync, DefaultRequestHeaders) for making the API request and Newtonsoft.Json (DeserializeObject\<T\>) for parsing the response.

---

<div class="post-metadata">

**Author:** ![Six](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/six/32/2334_2.png) [@Six](https://discuss.dev.twitch.com/u/Six)\
**Post date:** [March 29, 2018, 12:58am UTC](https://discuss.dev.twitch.com/t/check-if-channel-is-live-c-discord/14958/7 "2018-03-29T00:58:44Z")

</div>

You don’t need to use a library, but it can expedite the process and make it a bit more friendly. The library I use to make rest requests is called [RestSharp](http://restsharp.org/). It’s easy to use and easy to customize. I also use [Newtonsoft](https://www.newtonsoft.com/json) in combination with RestSharp to deserialize the result. RestSharp has a native serializer, but Newtonsoft is much more powerful, feature rich, and faster.

But, this is all for quality of life purposes. You can do all of this with the .NET framework in C# if you really wanted to.

---

<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:** [April 28, 2018, 1:03am UTC](https://discuss.dev.twitch.com/t/check-if-channel-is-live-c-discord/14958/8 "2018-04-28T01:03:49Z")

</div>

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