Twitch chat integration plugin for ElizaOS agents.
- Real-time Chat: Connect to Twitch channels and participate in chat
- Multi-channel Support: Join and monitor multiple channels simultaneously
- Role-based Access Control: Filter interactions by user roles (broadcaster, moderator, VIP, subscriber)
- Mention Detection: Optionally only respond when @mentioned
- Token Refresh: Automatic OAuth token refresh (when configured)
- Markdown Stripping: Automatically converts markdown to plain text for Twitch
npm install @elizaos/plugin-twitch- Twitch Developer Account: Register your application at Twitch Developer Console
- OAuth Token: Generate a token with
chat:readandchat:editscopes at Twitch Token Generator
Set the following environment variables:
| Variable | Description |
|---|---|
TWITCH_USERNAME |
Bot's Twitch username |
TWITCH_CLIENT_ID |
Application client ID from Twitch Developer Console |
TWITCH_ACCESS_TOKEN |
OAuth access token with chat:read and chat:edit scopes |
TWITCH_CHANNEL |
Primary channel to join (without # prefix) |
| Variable | Description | Default |
|---|---|---|
TWITCH_CLIENT_SECRET |
Application client secret (for token refresh) | - |
TWITCH_REFRESH_TOKEN |
OAuth refresh token (for automatic refresh) | - |
TWITCH_CHANNELS |
Comma-separated list of additional channels | - |
TWITCH_REQUIRE_MENTION |
Only respond when @mentioned | false |
TWITCH_ALLOWED_ROLES |
Comma-separated roles allowed to interact | all |
all- Anyone can interactowner/broadcaster- Channel owner onlymoderator- Moderatorsvip- VIP userssubscriber- Subscribers
import twitchPlugin from "@elizaos/plugin-twitch";
const agent = new Agent({
plugins: [twitchPlugin],
});Send a message to a Twitch channel.
// User: "Send a message saying 'Hello everyone!'"
// Agent will send to the current channelJoin a new Twitch channel.
// User: "Join the channel xqc"
// Agent will join #xqcLeave a Twitch channel.
// User: "Leave the channel xqc"
// Agent will leave #xqc (cannot leave primary channel)List all channels the bot is currently in.
// User: "What channels are you in?"
// Agent will list all joined channelsProvides context about the current Twitch channel:
- Channel name
- Whether it's the primary channel
- List of all joined channels
- Bot username
Provides context about the user in the conversation:
- User ID and username
- Display name
- Roles (broadcaster, moderator, VIP, subscriber)
- Chat color
The plugin emits the following events:
| Event | Description |
|---|---|
TWITCH_MESSAGE_RECEIVED |
A chat message was received |
TWITCH_MESSAGE_SENT |
A message was sent |
TWITCH_JOIN_CHANNEL |
Bot joined a channel |
TWITCH_LEAVE_CHANNEL |
Bot left a channel |
TWITCH_CONNECTION_READY |
Connected to Twitch |
TWITCH_CONNECTION_LOST |
Connection lost |
- Maximum message length: 500 characters
- Messages longer than 500 characters are automatically split
- Token Security: Never expose your access token in client-side code
- Scope Limitation: Only request necessary OAuth scopes
- Role Filtering: Use
TWITCH_ALLOWED_ROLESto restrict who can interact - Mention Requirement: Enable
TWITCH_REQUIRE_MENTIONin busy channels
- Verify your OAuth token is valid and not expired
- Check that the username matches the token owner
- Ensure the client ID is correct
- Regenerate your OAuth token
- Verify scopes include
chat:readandchat:edit - Check for typos in environment variables
- Verify you have joined the target channel
- Check that the channel name is correct (no # prefix)
- Ensure your token has
chat:editscope
This plugin supports:
- TypeScript - Full implementation with @twurple/chat
- Python - Full implementation with twitchio
- Rust - Full implementation with native WebSocket
MIT