---
title: "Twitch API - s&box library"
description: "A stupid simple Library that allows you to subscribe to events from Twitch Chat, with additional metadata for users/messages."
canonical: "https://sbox.watch/libraries/carsonk/twitchapi/"
generated_at: "2026-07-22T23:10:23.126Z"
---

# Twitch API

A stupid simple Library that allows you to subscribe to events from Twitch Chat, with additional metadata for users/messages.

- Type: library
- Ident: carsonk.twitchapi
- Creator: Carson Kompon
- Canonical: https://sbox.watch/libraries/carsonk/twitchapi/
- Markdown: https://sbox.watch/libraries/carsonk/twitchapi.md
- sbox.game: https://sbox.game/carsonk/twitchapi/
- Generated: 2026-07-22T23:10:23.126Z

## Stats

- 24h momentum: +0
- Terry score: --
- Favorites: 0
- Upvotes: 0
- Downvotes: 0
- Updated: Oct 10, 2024
- Created: Oct 10, 2024
- Size: 145.4 KB
- Files: 26
- Tags: twitch, ttv, api, utilities, utils, stream, chat

## Description

Twitch API

A stupid simple Library that allows you to subscribe to events from Twitch Chat, with additional metadata such as Badges, Emotes, whether or not a user is Moderator, Subscriber, Turbo, ect.

Here's how you do suff via code:

using TwitchAPI;

public class MyComponent : Component
{
 TwitchChatConnection TwitchChat;
 List<TwitchChatMessage> MessageHistory { get; set; }

 protected override void OnEnabled()
 {
 // Connect to the Chat
 TwitchChat = new TwitchChatConnection("CarsonKompon");

 // Subscribe to the different events
 TwitchChat.OnMessageReceieved += OnMessageReceieved;
 TwitchChat.OnMessagesCleared += OnMessagesCleared;
 }

 protected override void OnDisabled()
 {
 if(TwitchChat is null) return;

 // Disconnect/Dispose of the connection
 TwitchChat?.Dispose();

 // Un-subscribe from the events
 TwitchChat.OnMessageReceieved -= OnMessageReceieved;
 TwitchChat.OnMessagesCleared -= OnMessagesCleared;
 }

 void OnMessageReceived(TwitchChatMessage message)
 {
 // Add the message to the message history
 MessageHistory.Add(message);

 // "!test" command that only works for Moderators and subs
 if(message.Message == "!test" && (message.User.IsModerator || message.User.IsSubscriber))
 {
 Log.Info("Testing!");
 return;
 }

 // Otherwise, print the message to the console
 Log.Info($"{message.Username}: {message.Message}");
 }

 void OnMessagesCleared()
 {
 // Clear the message history
 MessageHistory.Clear();
 }
}

There's also a TwitchComponent included which can be used for simple ActionGraph-based solutions.



## More by Carson Kompon

| Package | Ident | Players | Favorites | Upvotes | Score | Markdown |
| --- | --- | --- | --- | --- | --- | --- |
| MediaHelpers | carsonk.mediahelpers | 0 | 15 | 10 | 79% | https://sbox.watch/libraries/carsonk/mediahelpers.md |
| Razor Panel Tooltips | carsonk.razor_tooltips | 0 | 6 | 5 | 50% | https://sbox.watch/libraries/carsonk/razor_tooltips.md |
| RichText Razor Panels | carsonk.richtextpanels | 0 | 3 | 4 | 60% | https://sbox.watch/libraries/carsonk/richtextpanels.md |
| Editor All Chat | carsonk.editor_all_chat | 0 | 2 | 6 | 69% | https://sbox.watch/libraries/carsonk/editor_all_chat.md |
| TikTokTTS | carsonk.tiktoktts | 0 | 1 | 4 | 60% | https://sbox.watch/libraries/carsonk/tiktoktts.md |
| SFXR | carsonk.sfxr | 0 | 1 | 2 | 43% | https://sbox.watch/libraries/carsonk/sfxr.md |
