---
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/zh-cn/libraries/carsonk/twitchapi/"
generated_at: "2026-11-27T12:31:25.180Z"
---

# Twitch API

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

- 类型: 库
- 标识符: carsonk.twitchapi
- 创作者: Carson Kompon
- 规范地址: https://sbox.watch/zh-cn/libraries/carsonk/twitchapi/
- Markdown: https://sbox.watch/zh-cn/libraries/carsonk/twitchapi/index.md
- sbox.game: https://sbox.game/carsonk/twitchapi/
- 生成时间: 2026-11-27T12:31:25.180Z

## 统计

- 24小时热度: +0
- Terry 评分: --
- 收藏: 0
- 好评: 0
- 差评: 0
- 更新时间: 2024年10月10日
- 创建时间: 2024年10月10日
- 大小: 145.4 KB
- 文件: 26
- 标签: twitch, ttv, api, utilities, utils, stream, chat

## 描述

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 | 标识符 | 玩家 | 收藏 | 好评 | 评分 | Markdown |
| --- | --- | --- | --- | --- | --- | --- |
| MediaHelpers | carsonk.mediahelpers | 0 | 15 | 10 | 79% | https://sbox.watch/zh-cn/libraries/carsonk/mediahelpers/index.md |
| Razor Panel Tooltips | carsonk.razor_tooltips | 0 | 6 | 6 | 55% | https://sbox.watch/zh-cn/libraries/carsonk/razor_tooltips/index.md |
| RichText Razor Panels | carsonk.richtextpanels | 0 | 3 | 4 | 60% | https://sbox.watch/zh-cn/libraries/carsonk/richtextpanels/index.md |
| TikTokTTS | carsonk.tiktoktts | 0 | 1 | 4 | 60% | https://sbox.watch/zh-cn/libraries/carsonk/tiktoktts/index.md |
| SFXR | carsonk.sfxr | 0 | 1 | 2 | 43% | https://sbox.watch/zh-cn/libraries/carsonk/sfxr/index.md |
| Granular Pitch Audio Processor | carsonk.granularpitchprocessor | 0 | 1 | 0 | -- | https://sbox.watch/zh-cn/libraries/carsonk/granularpitchprocessor/index.md |
