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

张开发
2026/4/18 18:43:40 15 分钟阅读

分享文章

OpenClaw从入门到应用——频道:Twitch
通过OpenClaw实现副业收入《OpenClaw赚钱实录从“养龙虾“到可持续变现的实践指南》Plugin requiredTwitch ships as a plugin and is not bundled with the core install. Install via CLI (npm registry):openclaw pluginsinstallopenclaw/twitchLocal checkout (when running from a git repo):openclaw pluginsinstall./extensions/twitchDetails: PluginsQuick setup (beginner)为机器人创建一个专用的 Twitch 账号或使用现有账号。生成凭证Twitch Token Generator选择Bot Token确认已勾选作用域chat:read和chat:write复制Client ID和Access Token查找你的 Twitch 用户 IDhttps://www.streamweasels.com/tools/convert-twitch-username-to-user-id/配置 token环境变量OPENCLAW_TWITCH_ACCESS_TOKEN...仅默认账户或配置文件channels.twitch.accessToken如果两者都设置配置文件优先环境变量仅作为默认账户的备选。启动 gateway。⚠️ 重要提示请添加访问控制allowFrom或allowedRoles以防止未授权用户触发机器人。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 isGateway 拥有的一个 Twitch 频道。确定性路由回复始终回到 Twitch。每个账户映射到一个独立的会话键agent::twitch:。username是机器人的账户谁进行身份验证channel是要加入的聊天室。Setup (detailed)Generate credentials使用 Twitch Token Generator选择Bot Token确认已勾选作用域chat:read和chat:write复制Client ID和Access Token无需手动注册应用程序。Token 会在几小时后过期。Configure the bot环境变量仅默认账户OPENCLAW_TWITCH_ACCESS_TOKENoauth: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 用户 IDhttps://www.streamweasels.com/tools/convert-twitch-username-to-user-id/将你的 Twitch 用户名转换为 IDToken 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 controlRole-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默认情况下requireMention为true。要禁用并响应所有消息{ channels: { twitch: { accounts: { default: { requireMention: false, }, }, }, }, }Troubleshooting首先运行诊断命令openclaw doctor openclaw channels status--probeBot doesn’t respond to messages检查访问控制确保你的用户 ID 在allowFrom中或者临时移除allowFrom并设置allowedRoles: [all]进行测试。检查机器人是否在频道中机器人必须加入channel指定的频道。Token issues“连接失败”或身份验证错误确认accessToken是 OAuth 访问令牌的值通常以oauth:前缀开头检查 token 是否具有chat:read和chat:write作用域如果使用 token 刷新请确认设置了clientSecret和refreshTokenToken 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确保提供了refreshTokenConfigAccount config:username- 机器人用户名accessToken- 具有chat:read和chat:write的 OAuth 访问令牌clientId- Twitch Client ID来自 Token Generator 或你自己的应用channel- 要加入的频道必需enabled- 启用此账户默认trueclientSecret- 可选用于自动刷新 tokenrefreshToken- 可选用于自动刷新 tokenexpiresIn- Token 过期时间秒obtainmentTimestamp- Token 获取时间戳allowFrom- 用户 ID 允许列表allowedRoles- 基于角色的访问控制moderator | owner | vip | subscriber | allrequireMention- 是否需要 提及默认trueProvider 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:read和chat:write如果卡住确认没有其他进程拥有该会话后重启 gatewayLimits每条消息500 个字符在单词边界自动分块分块前会去除 Markdown 格式无速率限制使用 Twitch 内置的速率限制

更多文章