PLEASE check the "Dev" build before doing a PR if master does not have a feature your looking for.
TwitchLib is a powerful C# library that allows for interaction with various Twitch services. Currently supported services are: chat and whisper, API's (v5(deprecated), helix, undocumented, and third party), EventSub, and Twitch Extensions. Below are the descriptions of the core components that make up TwitchLib.
Talk directly with us on Discord. https://discord.gg/8NXaEyV
- TwitchLib.Client: Handles chat and whisper Twitch services. Complete with a suite of events that fire for virtually every piece of data received from Twitch. Helper methods also exist for replying to whispers or fetching moderator lists.
- TwitchLib.Api: Complete coverage of v5(deprecated), and Helix endpoints. The API is now a singleton class. This class allows fetching all publicly accessible data as well as modify Twitch services like profiles and streams.
- TwitchLib.Extension: EBS implementation for validating requests, interacting with extension via PubSub and calling Extension endpoints.
- TwitchLib.Unity: Unity wrapper system for TwitchLib to allow easy usage of TwitchLib in Unity projects!
- TwitchLib.EventSub.Webhooks: EventSub implementation via webhooks for ASP.NET Core.
- TwitchLib.EventSub.Websockets: EventSub implementation via websocket.
- TwitchLib.Client:
- Send formatted or raw messages to Twitch
- Chat and Whisper command detection and parsing
- Handles chat and whisper events:
- Connected and Joined channel
- Channel and User state changed
- Message received/sent
- Whisper received/sent (Sending requires a known/verified bot)
- User joined/left
- Moderator joined/left
- New subscriptions and resubscriptions
- Hosting and raid detection
- Chat clear, user timeouts, user bans
- TwitchLib.APi:
- Supported Twitch API endpoints:v5(deprecated), Helix
- Supported API sections:
- Badges, Bits, Blocks
- ChannelFeeds, Channels, Chat, Clips, Collections, Communities,
- Follows
- Games
- HypeTrain
- Ingests
- Root
- Search, Streams, Subscriptions
- Teams
- ThirdParty
- Moderator Lookup courtesy of 3v's https://t.3v.fi
- Twitch Authentication Flow courtesy of swiftyspiffy's https://twitchtokengenerator.com/
- Undocumented
- ClipChat
- TwitchPrimeOffers
- ChannelHosts
- ChatProperties
- ChannelPanels
- CSMaps
- CSStreams
- RecentMessages
- Chatters
- RecentChannelEvents
- ChatUser
- UsernameAvailable
- User
- Videos
- Services
- FollowerService: Service for detection of new followers in somewhat real time.
- LiveStreamMonitor: Service for detecting when a channel goes online/offline in somewhat real time.
- MessageThrottler: Service to throttle chat messages to abide by Twitch use requirements.
- TwitchLib.Extension:
- Developed to be used as part of an EBS (extension back-end service) for a Twitch Extension.
- Perform API calls related to Extensions (create secret, revoke, channels using extension, etc.)
- Validation of requests to EBS using extension secret and JWT.
- Interact with extension via PubSub.
For complete library documentation, view the doxygen docs here.
Below are basic examples of how to utilize each of the core components of TwitchLib. These are C# examples. NOTE: Twitchlib.API currently does not support Visual Basic. UPDATE: PR'd Visual Basic fix but requires testing by someone that uses it.
See the Client README https://github.com/TwitchLib/TwitchLib.Client.
For a complete list of TwitchClient events and calls, click here
Note: TwitchAPI is now a singleton class that needs to be instantiated with optional clientid and auth token. Please know that failure to provide at least a client id, and sometimes an access token will result in exceptions. v5(Deprecated) and Helix operate almost entirely on Twitch user id's. There are methods in all Twitch api versions to get corresponding usernames/userids.
using System.Collections.Generic;
using System.Threading.Tasks;
using TwitchLib.Api;
using TwitchLib.Api.Helix.Models.Users;
using TwitchLib.Api.V5.Models.Subscriptions; //v5 Deprecated
namespace Example
{
class Program
{
private static TwitchAPI api;
private void Main()
{
api = new TwitchAPI();
api.Settings.ClientId = "client_id";
api.Settings.AccessToken = "access_token"; // App Secret is not an Accesstoken
}
private async Task ExampleCallsAsync()
{
//Gets a list of all the subscritions of the specified channel.
var allSubscriptions = await api.Helix.Subscriptions.GetBroadcasterSubscriptionsAsync("broadcasterID",null ,100 ,"accesstoken")
//Get channels a specified user follows.
var userFollows = await api.Helix.Users.GetUsersFollowsAsync("user_id");
//Get Specified Channel Follows
var channelFollowers = await api.Helix.Users.GetUsersFollowsAsync(fromId: "channel_id");
//Returns a stream object if online, if channel is offline it will be null/empty.
var streams = await api.Helix.Streams.GetStreamsAsync(userIds: userIdsList); // Alternative: userLogins: userLoginsList
//Update Channel Title/Game/Language/Delay - Only require 1 option here.
var request = new ModifyChannelInformationRequest(){GameId = "New_Game_Id", Title = "New stream title", BroadcasterLanguage = "New_Language", Delay = New_Delay};
await api.Helix.Channels.ModifyChannelInformationAsync("broadcaster_Id", request, "AccessToken");
}
}
}Imports System.Collections.Generic
Imports System.Threading.Tasks
Imports TwitchLib.Api
Imports TwitchLib.Api.Models.Helix.Users.GetUsersFollows
Imports TwitchLib.Api.Models.Helix.Users.GetUsers
Imports TwitchLib.Api.Models.v5.Subscriptions // V5 deprecated
Module Module1
Public api As TwitchAPI
Sub Main()
api = New TwitchAPI()
api.Settings.ClientId = "Client_id"
api.Settings.AccessToken = "access_token" // App Secret is not an Accesstoken
streaming().Wait()
getchanfollows().Wait()
getusersubs().Wait()
getnumberofsubs().Wait()
getsubstochannel().Wait()
Console.ReadLine()
End Sub
Private Async Function getusersubs() As Task
'Checks subscription for a specific user and the channel specified.
Dim subscription As Subscription = Await api.Channels.v5.CheckChannelSubscriptionByUserAsync("channel_id", "user_id")
Console.WriteLine("User subed: " + subscription.User.Name.ToString)
End Function
Private Async Function streaming() As Task
'shows if the channel is streaming or not (true/false)
Dim isStreaming As Boolean = Await api.Streams.v5.BroadcasterOnlineAsync("channel_id")
If isStreaming = True Then
Console.WriteLine("Streaming")
Else
Console.WriteLine("Not Streaming")
End If
End Function
Private Async Function chanupdate() As Task
'Update Channel Title/Game
'not used this yet
Await api.Channels.v5.UpdateChannelAsync("channel_id", "New stream title", "Stronghold Crusader")
End Function
Private Async Function getchanfollows() As Task
'Get Specified Channel Follows
Dim channelFollowers = Await api.Channels.v5.GetChannelFollowersAsync("channel_id")
Console.WriteLine(channelFollowers.Total.ToString)
End Function
Private Async Function getchanuserfollow() As Task
'Get channels a specified user follows.
Dim userFollows As GetUsersFollowsResponse = Await api.Users.helix.GetUsersFollowsAsync("user_id")
Console.WriteLine(userFollows.TotalFollows.ToString)
End Function
Private Async Function getnumberofsubs() As Task
'Get the number of subs to your channel
Dim numberofsubs = Await api.Channels.v5.GetChannelSubscribersAsync("channel_id")
Console.WriteLine(numberofsubs.Total.ToString)
End Function
Private Async Function getsubstochannel() As Task
'Gets a list of all the subscritions of the specified channel.
Dim allSubscriptions As List(Of Subscription) = Await api.Channels.v5.GetAllSubscribersAsync("channel_id")
Dim num As Integer
For num = 0 To allSubscriptions.Count - 1
Console.WriteLine(allSubscriptions.Item(num).User.Name.ToString)
Next num
End Function
End ModuleFor a complete list of TwitchAPI calls, click here
See the Extension README here.
NOTE: Use these projects as a reference, they are NOT guaranteed to be up-to-date.
If you have any issues using these examples, please indicate what example you are referencing in the Issue or in Discord.
- Recent commits in projects using TwitchLib: Link
- Bacon_Donut's VOD on building a Twitch bot using TwitchLib: twitch.tv/videos/115788601
- Prom3theu5's Conan Exiles Dedicated Server Updater / Service - Steam Github
- Von Jan Suchotzki's German Video Tutorial Series - His Website Youtube
- DHSean's TwitchAutomator Reddit Github
- Moerty's Avia Bot, a fully featured bot that is a good example of a built out bot: https://github.com/Moerty/AivaBot
- HardlyDifficult's Chat Bot Creation VODs: #1 #2 #3 #4
- Prom3theu5's TwitchBotBase - github.com/prom3theu5/TwitchBotBase
- Trump Academi's ASP.NET TwitchLib Implementation - trumpacademi.com/day-9-twitch-bot-and-mvc-asp-net-implementing-twitchlib/
- ubhkid's Zombie Twitch chat game/overlay - reddit.com/r/Unity3D/comments/6ll10k/i_made_a_game_for_my_twitch_chat/
- FPH SpedV: Virtual Freight Company Tool - sped-v.de
- Foglio's Tera Custom Cooldowns - Tera Custom Cooldowns
To install this library via NuGet via NuGet console, use:
Install-Package TwitchLib
and via Package Manager, simply search:
TwitchLib
You are also more than welcome to clone/fork this repo and build the library yourself!
- Newtonsoft.Json 7.0.1+ (nuget link) (GitHub)
- WebSocketSharp-NonPreRelease (nuget link) (GitHub)
- Cole (swiftyspiffy)
- SkyHuk (SkyHukTV)
- Nadermane (Nadermane)
- BenWoodford (BenWoodford)
- igor523 (igor523)
- jxlarrea (jxlarrea)
- GlitchHound (GlitchHound)
- Krutonium (Krutonium)
- toffaste1337(toffaste1337)
- Mr_Examed (Mr_Examed)
- XuluniX (XuluniX)
- prom3theu5 (prom3theu5)
- Ethan Lu (elu00)
- BeerHawk (BeerHawk)
- Syzuna (Syzuna)
- LuckyNoS7evin (luckynos7evin)
- Peter Richter (DumpsterDoofus)
- Mahsaap (Mahsaap)
- neon-sunset (neon-sunset)
- AoshiW (AoshiW)
- JulanDeAlb (JulanDeAlb)
- GimliCZ (GimliCZ)
- Bukk94 (Bukk94)
- TwitchChatSharp - https://github.com/3ventic/TwitchChatSharp
- We used a good portion of the parsing in this project to improve our parsing. Special thanks to @3ventic.
This project is available under the MIT license. See the LICENSE file for more info.
:)
