Twitch (plugin)
Twitch chat support via IRC connection. Moltbot connects as a Twitch user (bot account) to receive and send messages in channels.Plugin required
Twitch ships as a plugin and is not bundled with the core install. Install via CLI (npm registry):Quick setup (beginner)
- Create a dedicated Twitch account for the bot (or use an existing account).
- Generate credentials: Twitch Token Generator
- Select Bot Token
- Verify scopes
chat:readandchat:writeare selected - Copy the Client ID and Access Token
- Find your Twitch user ID: https://www.streamweasels.com/tools/convert-twitch-username-to-user-id/
- Configure the token:
- Env:
CLAWDBOT_TWITCH_ACCESS_TOKEN=...(default account only) - Or config:
channels.twitch.accessToken - If both are set, config takes precedence (env fallback is default-account only).
- Env:
- Start the gateway.
allowFrom or allowedRoles) to prevent unauthorized users from triggering the bot. requireMention defaults to true.
Minimal config:
What it is
- A Twitch channel owned by the Gateway.
- Deterministic routing: replies always go back to Twitch.
- Each account maps to an isolated session key
agent:<agentId>:twitch:<accountName>. usernameis the bot’s account (who authenticates),channelis which chat room to join.
Setup (detailed)
Generate credentials
Use Twitch Token Generator:- Select Bot Token
- Verify scopes
chat:readandchat:writeare selected - Copy the Client ID and Access Token
Configure the bot
Env var (default account only):Access control (recommended)
"moderator", "owner", "vip", "subscriber", "all".
Why user IDs? Usernames can change, allowing impersonation. User IDs are permanent.
Find your Twitch user ID: https://www.streamweasels.com/tools/convert-twitch-username-%20to-user-id/ (Convert your Twitch username to ID)
Token refresh (optional)
Tokens from Twitch Token Generator cannot be automatically refreshed - regenerate when expired. For automatic token refresh, create your own Twitch application at Twitch Developer Console and add to config:Multi-account support
Usechannels.twitch.accounts with per-account tokens. See gateway/configuration for the shared pattern.
Example (one bot account in two channels):
Access control
Role-based restrictions
Allowlist by User ID (most secure)
Combined allowlist + roles
Users inallowFrom bypass role checks:
Disable @mention requirement
By default,requireMention is true. To disable and respond to all messages:
Troubleshooting
First, run diagnostic commands:Bot doesn’t respond to messages
Check access control: Temporarily setallowedRoles: ["all"] to test.
Check the bot is in the channel: The bot must join the channel specified in channel.
Token issues
“Failed to connect” or authentication errors:- Verify
accessTokenis the OAuth access token value (typically starts withoauth:prefix) - Check token has
chat:readandchat:writescopes - If using token refresh, verify
clientSecretandrefreshTokenare set
Token refresh not working
Check logs for refresh events:- Ensure
clientSecretis provided - Ensure
refreshTokenis provided
Config
Account config:username- Bot usernameaccessToken- OAuth access token withchat:readandchat:writeclientId- Twitch Client ID (from Token Generator or your app)channel- Channel to join (required)enabled- Enable this account (default:true)clientSecret- Optional: For automatic token refreshrefreshToken- Optional: For automatic token refreshexpiresIn- Token expiry in secondsobtainmentTimestamp- Token obtained timestampallowFrom- User ID allowlistallowedRoles- Role-based access control ("moderator" | "owner" | "vip" | "subscriber" | "all")requireMention- Require @mention (default:true)
channels.twitch.enabled- Enable/disable channel startupchannels.twitch.username- Bot username (simplified single-account config)channels.twitch.accessToken- OAuth access token (simplified single-account config)channels.twitch.clientId- Twitch Client ID (simplified single-account config)channels.twitch.channel- Channel to join (simplified single-account config)channels.twitch.accounts.<accountName>- Multi-account config (all account fields above)
Tool actions
The agent can calltwitch with action:
send- Send a message to a channel
Safety & ops
- Treat tokens like passwords - Never commit tokens to git
- Use automatic token refresh for long-running bots
- Use user ID allowlists instead of usernames for access control
- Monitor logs for token refresh events and connection status
- Scope tokens minimally - Only request
chat:readandchat:write - If stuck: Restart the gateway after confirming no other process owns the session
Limits
- 500 characters per message (auto-chunked at word boundaries)
- Markdown is stripped before chunking
- No rate limiting (uses Twitch’s built-in rate limits)