跳到主要内容

Discord 设置

概述

Discord channel 把 Anyy 连接到 Discord 私信和服务器。Adapter 支持 DM、群组/服务器会话、thread context、inbound media、lifecycle startup 和 live-smoke 检查。

Anyy 仍然是 assistant;Discord 只是接收消息和发送回复的 surface。

前提条件

  • 一个带 bot user 的 Discord application。
  • Bot token。
  • Bot 已邀请到需要响应的 server 或 channel。
  • Bot 有读消息和发消息权限。
  • 如果要可靠过滤自己的消息,准备 bot user id。

配置

创建凭据

在 Discord developer portal 创建或复用 bot token。不要把 token 写进 config.yaml;Anyy 会把它保存为 profile secret。

配置 Anyy

anyy setup channels discord \
--secret bot_token='discord-bot-token' \
--write-config

setup helper 会写入 channels.discord,默认值:

字段默认值
account_idwork
dm_policypairing
group_policymention
allow_from[]
allow_groups[]
media_max_bytes5242880

需要时加可选字段:

channels:
discord:
bot_user_id: "1234567890"
send_chunk_chars: 3800

启动 Gateway

anyy gateway start
anyy channels reload

运行 Doctor 检查

anyy channels doctor discord

Doctor 检查配置和 secret ref,不会替你设置 Discord 权限。

访问策略

私信

setup 默认写入 dm_policy: pairing。若要更严格,改用 allowlist:

channels:
discord:
dm_policy: allowlist
allow_from:
- "discord-user-id"

群组

默认 group_policy: mention,表示 Discord 群组或 server context 中只有提到 bot 时才会响应。只允许特定 channel 时,配合 allow_groupsallowlist

管理员

Discord channel policy 只控制消息准入。管理类命令仍由共享 messaging command 权限控制。

Sessions

Anyy 会为每个被接受的 Discord conversation 保持独立 session。Discord 发送 thread 信息时,回复会留在对应 context。

媒体支持

入站媒体

Discord 声明支持 inbound media。Anyy 可接收不超过 media_max_bytes 的附件。

出站媒体

这个 adapter 没有声明原生 outbound media。生成的 artifact 仍会保存在 Anyy session 中。

命令

使用与其他 channel 相同的 messaging commands。Server 里如果 group_policymention,需要提到 bot。

Cron 投递

有默认绑定或 delivery target 后,cron 可以投递到 Discord:

anyy cron create \
--name "Discord summary" \
--schedule "0 9 * * *" \
--prompt "Post my morning summary" \
--delivery-target current_user_default \
--delivery-channel discord

故障排查

  • Server 里 bot 不响应:检查 group_policy、是否提到 bot、以及 Discord channel 权限。
  • DM 被拒绝:检查 dm_policyallow_from
  • 出现自回复或循环:设置 bot_user_id
  • 附件被忽略:确认文件大小低于 media_max_bytes