




通过 IRC 连接支持 Twitch 聊天。OpenClaw 以 Twitch 用户(机器人账户)身份连接,在频道中接收和发送消息。
Twitch 作为插件发布,未与核心安装捆绑。 通过 CLI 安装(npm 注册表):
openclaw plugins install @openclaw/twitch
本地检出(从 git 仓库运行时):
openclaw plugins install ./extensions/twitch
详情:插件
chat:read和chat:write权限范围OPENCLAWTWITCHACCESS_TOKEN=...(仅限默认账户)channels.twitch.accessToken⚠️ 重要:添加访问控制(allowFrom或allowedRoles)以防止未授权用户触发机器人。requireMention默认为true。
最小配置:
{ channels: { twitch: { enabled: true, username: "openclaw", // 机器人的 Twitch 账户 accessToken: "oauth:abc123...", // OAuth Access Token(或使用 OPENCLAWTWITCHACCESS_TOKEN 环境变量) clientId: "xyz789...", // Token Generator 中的 Client ID channel: "vevisk", // 要加入的 Twitch 频道聊天(必填) allowFrom: ["123456789"], // (推荐)仅限你的 Twitch 用户 ID - 从 https://www.streamweasels.com/tools/convert-twitch-username-to-user-id/ 获取 }, }, }agent:<agentId:twitch:<accountName。username是机器人账户(进行身份验证的账户),channel是要加入的聊天室。chat:read和chat:write权限范围无需手动注册应用。令牌在几小时后过期。
环境变量(仅限默认账户):
OPENCLAWTWITCHACCESS_TOKEN=oauth:abc123...
或配置:
{ channels: { twitch: { enabled: true, username: "openclaw", accessToken: "oauth:abc123...", clientId: "xyz789...", channel: "vevisk", }, }, }如果环境变量和配置都设置了,配置优先。
{ channels: { twitch: { allowFrom: ["123456789"], // (推荐)仅限你的 Twitch 用户 ID }, }, }优先使用allowFrom作为硬性允许列表。如果你想要基于角色的访问控制,请改用allowedRoles。
可用角色:"moderator"、"owner"、"vip"、"subscriber"、"all"。
为什么用用户 ID?
用户名可以更改,允许冒充。用户 ID 是永久的。 查找你的 Twitch 用户 ID:https://www.streamweasels.com/tools/convert-twitch-username-%20to-user-id/(将你的Twitch 用户名转换为 ID)
来自Twitch Token Generator的令牌无法自动刷新 - 过期时需要重新生成。 要实现自动令牌刷新,请在Twitch Developer Console创建你自己的 Twitch 应用并添加到配置中:
{ channels: { twitch: { clientSecret: "yourclientsecret", refreshToken: "yourrefreshtoken", }, }, }机器人会在令牌过期前自动刷新,并记录刷新事件。
使用channels.twitch.accounts配置每个账户的令牌。参阅gateway/configuration了解共享模式。 示例(一个机器人账户在两个频道中):
{ channels: { twitch: { accounts: { channel1: { username: "openclaw", accessToken: "oauth:abc123...", clientId: "xyz789...", channel: "vevisk", }, channel2: { username: "openclaw", accessToken: "oauth:def456...", clientId: "uvw012...", channel: "secondchannel", }, }, }, }, }注意:每个账户需要自己的令牌(每个频道一个令牌)。
{ channels: { twitch: { accounts: { default: { allowedRoles: ["moderator", "vip"], }, }, }, }, }{ channels: { twitch: { accounts: { default: { allowFrom: ["123456789", "987654321"], }, }, }, }, }allowFrom是硬性允许列表。设置后,只允许这些用户 ID。 如果你想要基于角色的访问,请不设置allowFrom,改为配置allowedRoles:
{ channels: { twitch: { accounts: { default: { allowedRoles: ["moderator"], }, }, }, }, }默认情况下,requireMention为true。要禁用并响应所有消息:
{ channels: { twitch: { accounts: { default: { requireMention: false, }, }, }, }, }首先,运行诊断命令:
openclaw doctor openclaw channels status --probe
检查访问控制:确保你的用户 ID 在allowFrom中,或临时移除allowFrom并设置allowedRoles: ["all"]来测试。
检查机器人是否在频道中:机器人必须加入channel中指定的频道。
“Failed to connect”或身份验证错误:
accessToken是 OAuth 访问令牌值(通常以oauth:前缀开头)chat:read和chat:write权限范围clientSecret和refreshToken已设置检查日志中的刷新事件:
Using env token source for mybot Access token refreshed for user 123456 (expires in 14400s)
如果你看到”token refresh disabled (no refresh token)”:
clientSecretrefreshToken账户配置:
username机器人用户名accessToken具有chat:read和chat:write权限的 OAuth 访问令牌clientIdTwitch Client ID(来自 Token Generator 或你的应用)channel要加入的频道(必填)enabled启用此账户(默认:true)clientSecret可选:用于自动令牌刷新refreshToken可选:用于自动令牌刷新expiresIn令牌过期时间(秒)obtainmentTimestamp令牌获取时间戳allowFrom用户 ID 允许列表allowedRoles基于角色的访问控制("moderator" | "owner" | "vip" | "subscriber" | "all")requireMention需要 @提及(默认:true)提供商选项:
channels.twitch.enabled启用/禁用渠道启动channels.twitch.username机器人用户名(简化的单账户配置)channels.twitch.accessTokenOAuth 访问令牌(简化的单账户配置)channels.twitch.clientIdTwitch Client ID(简化的单账户配置)channels.twitch.channel要加入的频道(简化的单账户配置)channels.twitch.accounts.<accountName多账户配置(以上所有账户字段)完整示例:
{ channels: { twitch: { enabled: true, username: "openclaw", accessToken: "oauth:abc123...", clientId: "xyz789...", channel: "vevisk", clientSecret: "secret123...", refreshToken: "refresh456...", allowFrom: ["123456789"], allowedRoles: ["moderator", "vip"], accounts: { default: { username: "mybot", accessToken: "oauth:abc123...", clientId: "xyz789...", channel: "your_channel", enabled: true, clientSecret: "secret123...", refreshToken: "refresh456...", expiresIn: 14400, obtainmentTimestamp: 1706092800000, allowFrom: ["123456789", "987654321"], allowedRoles: ["moderator"], }, }, }, }, }智能体可以调用twitch执行以下操作:
send向频道发送消息示例:
{ action: "twitch", params: { message: "Hello Twitch!", to: "#mychannel", }, }chat:read和chat:write