Twitch(插件)
通过 IRC 连接支持 Twitch 聊天。OpenClaw 以 Twitch 用户(bot 账号)身份连接到频道,收发消息。需要插件
Twitch 为插件形式,未随核心安装打包。 通过 CLI 安装(npm registry):快速设置(新手)
- 为 bot 创建一个专用 Twitch 账号(或使用已有账号)。
- 生成凭据:Twitch Token Generator
- 选择 Bot Token
- 确认勾选
chat:read和chat:writescopes - 复制 Client ID 和 Access Token
- 查找你的 Twitch 用户 ID: https://www.streamweasels.com/tools/convert-twitch-username-to-user-id/
- 配置 token:
- 环境变量:
OPENCLAW_TWITCH_ACCESS_TOKEN=...(仅默认账号) - 或配置:
channels.twitch.accessToken - 两者都设置时以配置优先(环境变量仅用于默认账号回退)。
- 环境变量:
- 启动 gateway。
allowFrom 或 allowedRoles)以防止未授权用户触发 bot。requireMention 默认是 true。
最小配置:
这是什么
- 由 Gateway 持有的 Twitch 渠道。
- 路由确定性:回复始终回到 Twitch。
- 每个账号映射到独立会话 key:
agent:<agentId>:twitch:<accountName>。 username是 bot 账号(用于认证),channel是要加入的聊天频道。
设置(详细)
生成凭据
使用 Twitch Token Generator:- 选择 Bot Token
- 确认勾选
chat:read与chat:write - 复制 Client ID 与 Access Token
配置 bot
环境变量(仅默认账号):访问控制(推荐)
"moderator"、"owner"、"vip"、"subscriber"、"all"。
为什么用用户 ID? 用户名可变,容易被冒名;用户 ID 是永久的。
查找你的 Twitch 用户 ID:
https://www.streamweasels.com/tools/convert-twitch-username-to-user-id/ (将 Twitch 用户名转换为 ID)
Token 刷新(可选)
通过 Twitch Token Generator 获取的 token 无法自动刷新 — 过期后需重新生成。 若需自动刷新,请在 Twitch Developer Console 创建应用,并添加到配置:多账号支持
使用channels.twitch.accounts 配置各账号 token。通用模式见 gateway/configuration。
示例(一个 bot 账号加入两个频道):
访问控制
角色限制
按用户 ID allowlist(最安全)
allowlist + roles 组合
allowFrom 中的用户会跳过角色检查:
禁用 @mention 要求
默认requireMention 为 true。若要对所有消息回复:
故障排查
先运行诊断命令:Bot 不回复消息
检查访问控制: 临时设置allowedRoles: ["all"] 测试。
确认 bot 在频道中: bot 必须加入 channel 指定的频道。
Token 问题
“Failed to connect” 或鉴权错误:- 确认
accessToken为 OAuth access token(通常带oauth:前缀) - 确认 token 具备
chat:read与chat:writescopes - 若使用刷新,确认
clientSecret与refreshToken已设置
Token 刷新不工作
检查日志中的刷新事件:- 确认已设置
clientSecret - 确认已设置
refreshToken
配置
账号配置:username- Bot 用户名accessToken- 具备chat:read与chat:write的 OAuth access tokenclientId- Twitch Client ID(来自 Token Generator 或自建应用)channel- 要加入的频道(必填)enabled- 启用该账号(默认:true)clientSecret- 可选:自动刷新所需refreshToken- 可选:自动刷新所需expiresIn- token 过期秒数obtainmentTimestamp- token 获取时间戳allowFrom- 用户 ID allowlistallowedRoles- 角色访问控制("moderator" | "owner" | "vip" | "subscriber" | "all")requireMention- 要求 @mention(默认:true)
channels.twitch.enabled- 启用/禁用渠道启动channels.twitch.username- Bot 用户名(单账号简化配置)channels.twitch.accessToken- OAuth access token(单账号简化配置)channels.twitch.clientId- Twitch Client ID(单账号简化配置)channels.twitch.channel- 要加入的频道(单账号简化配置)channels.twitch.accounts.<accountName>- 多账号配置(包含上述账号字段)
工具动作
agent 可调用twitch 动作:
send- 向频道发送消息
安全与运维
- 将 token 视作密码 — 不要提交到 git
- 使用自动刷新 适配长时间运行的 bot
- 使用用户 ID allowlist 代替用户名进行访问控制
- 监控日志 关注 token 刷新与连接状态
- 最小化 scopes — 仅请求
chat:read与chat:write - 若卡住:确认无其他进程占用会话后重启 gateway
限制
- 每条消息500 字符(按单词边界自动分块)
- 分块前会移除 Markdown
- 不提供额外限流(使用 Twitch 内置速率限制)