news 2026/4/16 16:25:00

OpenClaw从入门到应用——频道:Twitch

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
OpenClaw从入门到应用——频道:Twitch

通过OpenClaw实现副业收入:《OpenClaw赚钱实录:从“养龙虾“到可持续变现的实践指南》

Plugin required

Twitch ships as a plugin and is not bundled with the core install. Install via CLI (npm registry):

openclaw pluginsinstall@openclaw/twitch

Local checkout (when running from a git repo):

openclaw pluginsinstall./extensions/twitch

Details: Plugins

Quick setup (beginner)

  1. 为机器人创建一个专用的 Twitch 账号(或使用现有账号)。
  2. 生成凭证:Twitch Token Generator
    • 选择Bot Token
    • 确认已勾选作用域chat:readchat:write
    • 复制Client IDAccess Token
  3. 查找你的 Twitch 用户 ID:https://www.streamweasels.com/tools/convert-twitch-username-to-user-id/
  4. 配置 token:
    • 环境变量:OPENCLAW_TWITCH_ACCESS_TOKEN=...(仅默认账户)
    • 或配置文件:channels.twitch.accessToken
    • 如果两者都设置,配置文件优先(环境变量仅作为默认账户的备选)。
  5. 启动 gateway。

⚠️ 重要提示:请添加访问控制(allowFromallowedRoles)以防止未授权用户触发机器人。requireMention默认为true

最小配置示例:

{ channels: { twitch: { enabled: true, username: "openclaw", // 机器人的 Twitch 账号 accessToken: "oauth:abc123...", // OAuth Access Token(或使用 OPENCLAW_TWITCH_ACCESS_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/ 获取 }, }, }

What it is

  • Gateway 拥有的一个 Twitch 频道。
  • 确定性路由:回复始终回到 Twitch。
  • 每个账户映射到一个独立的会话键agent::twitch:
  • username是机器人的账户(谁进行身份验证),channel是要加入的聊天室。

Setup (detailed)

Generate credentials

使用 Twitch Token Generator:

  • 选择Bot Token
  • 确认已勾选作用域chat:readchat:write
  • 复制Client IDAccess Token

无需手动注册应用程序。Token 会在几小时后过期。

Configure the bot

环境变量(仅默认账户):

OPENCLAW_TWITCH_ACCESS_TOKEN=oauth:abc123...

或配置文件:

{ channels: { twitch: { enabled: true, username: "openclaw", accessToken: "oauth:abc123...", clientId: "xyz789...", channel: "vevisk", }, }, }

如果同时设置了环境变量和配置文件,配置文件优先。

Access control (recommended)

{ 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-to-user-id/(将你的 Twitch 用户名转换为 ID)

Token refresh (optional)

来自 Twitch Token Generator 的 token 无法自动刷新——过期后请重新生成。

如需自动刷新 token,请在 Twitch Developer Console 创建自己的 Twitch 应用程序,并添加到配置中:

{ channels: { twitch: { clientSecret: "your_client_secret", refreshToken: "your_refresh_token", }, }, }

机器人会在 token 过期前自动刷新,并记录刷新事件。

Multi-account support

使用channels.twitch.accounts配合每个账户的独立 token。通用模式请参见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", }, }, }, }, }

注意:每个账户需要自己的 token(每个频道一个 token)。

Access control

Role-based restrictions

{ channels: { twitch: { accounts: { default: { allowedRoles: ["moderator", "vip"], }, }, }, }, }

Allowlist by User ID (most secure)

{ channels: { twitch: { accounts: { default: { allowFrom: ["123456789", "987654321"], }, }, }, }, }

Role-based access (alternative)

allowFrom是一个硬性允许列表。设置后,仅允许这些用户 ID。如果你希望使用基于角色的访问,请不设置allowFrom,而是配置allowedRoles

{ channels: { twitch: { accounts: { default: { allowedRoles: ["moderator"], }, }, }, }, }

Disable @mention requirement

默认情况下,requireMentiontrue。要禁用并响应所有消息:

{ channels: { twitch: { accounts: { default: { requireMention: false, }, }, }, }, }

Troubleshooting

首先,运行诊断命令:

openclaw doctor openclaw channels status--probe

Bot doesn’t respond to messages

检查访问控制:确保你的用户 ID 在allowFrom中,或者临时移除allowFrom并设置allowedRoles: ["all"]进行测试。

检查机器人是否在频道中:机器人必须加入channel指定的频道。

Token issues

“连接失败”或身份验证错误:

  • 确认accessToken是 OAuth 访问令牌的值(通常以oauth:前缀开头)
  • 检查 token 是否具有chat:readchat:write作用域
  • 如果使用 token 刷新,请确认设置了clientSecretrefreshToken

Token refresh not working

检查日志中的刷新事件:

Using env token source for mybot Access token refreshed for user 123456 (expires in 14400s)

如果看到 “token refresh disabled (no refresh token)”:

  • 确保提供了clientSecret
  • 确保提供了refreshToken

Config

Account config:

  • username- 机器人用户名
  • accessToken- 具有chat:readchat:write的 OAuth 访问令牌
  • clientId- Twitch Client ID(来自 Token Generator 或你自己的应用)
  • channel- 要加入的频道(必需)
  • enabled- 启用此账户(默认:true
  • clientSecret- 可选:用于自动刷新 token
  • refreshToken- 可选:用于自动刷新 token
  • expiresIn- Token 过期时间(秒)
  • obtainmentTimestamp- Token 获取时间戳
  • allowFrom- 用户 ID 允许列表
  • allowedRoles- 基于角色的访问控制("moderator" | "owner" | "vip" | "subscriber" | "all"
  • requireMention- 是否需要 @提及(默认:true

Provider options:

  • channels.twitch.enabled- 启用/禁用频道启动
  • channels.twitch.username- 机器人用户名(简化单账户配置)
  • channels.twitch.accessToken- OAuth 访问令牌(简化单账户配置)
  • channels.twitch.clientId- Twitch Client ID(简化单账户配置)
  • channels.twitch.channel- 要加入的频道(简化单账户配置)
  • channels.twitch.accounts- 多账户配置(包含上述所有账户字段)

完整示例:

{ 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"], }, }, }, }, }

Tool actions

代理可以调用twitch并执行以下操作:

  • send- 向频道发送消息

示例:

{ action: "twitch", params: { message: "Hello Twitch!", to: "#mychannel", }, }

Safety & ops

  • 将 token 视为密码- 切勿将 token 提交到 git
  • 对长期运行的机器人使用自动 token 刷新
  • 使用用户 ID 允许列表而不是用户名进行访问控制
  • 监控日志以查看 token 刷新事件和连接状态
  • 最小化 token 作用域- 仅请求chat:readchat:write
  • 如果卡住:确认没有其他进程拥有该会话后,重启 gateway

Limits

  • 每条消息500 个字符(在单词边界自动分块)
  • 分块前会去除 Markdown 格式
  • 无速率限制(使用 Twitch 内置的速率限制)
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/4/16 16:24:42

3步解锁网盘直链下载:告别限速瓶颈的浏览器原生方案

3步解锁网盘直链下载:告别限速瓶颈的浏览器原生方案 【免费下载链接】Online-disk-direct-link-download-assistant 一个基于 JavaScript 的网盘文件下载地址获取工具。基于【网盘直链下载助手】修改 ,支持 百度网盘 / 阿里云盘 / 中国移动云盘 / 天翼云…

作者头像 李华
网站建设 2026/4/16 16:23:42

从根轨迹到伯德图:一个实际案例讲透超前补偿器如何拯救你的不稳定系统

从根轨迹到伯德图:一个实际案例讲透超前补偿器如何拯救你的不稳定系统 控制系统工程师常常面临这样的困境:精心设计的系统在仿真中表现完美,实际运行时却振荡不止。上周我调试一台工业机械臂时就遇到了这个问题——每当执行高速轨迹跟踪时&am…

作者头像 李华
网站建设 2026/4/16 16:22:15

Windows苹果设备驱动终极安装指南:告别iPhone连接烦恼

Windows苹果设备驱动终极安装指南:告别iPhone连接烦恼 【免费下载链接】Apple-Mobile-Drivers-Installer Powershell script to easily install Apple USB and Mobile Device Ethernet (USB Tethering) drivers on Windows! 项目地址: https://gitcode.com/gh_mir…

作者头像 李华