mcpField
D
discord

discord

github.com/acedatacloud生产力17174 次安装今天更新
代码仓库

关于 discord

通过命令行操作用户 Discord 账号的技能。用户令牌模式支持频道和消息操作,OAuth 模式仅能读取身份与服务器列表。

主要功能

  1. 01查询身份与服务器
  2. 02列出频道并读取消息
  3. 03经确认后发送或回复
  4. 04OAuth 只读访问身份和服务器

适用场景

  1. 01查看频道近期消息
  2. 02发送经批准的消息或回复
  3. 03检查账号身份与服务器成员关系

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/acedatacloud/skills --skill discord

安装后在 Claude Code 中输入/discord确认已加载。

附带文件scripts/discord_user.py

详细介绍

discord — 使用用户的 Discord 账号

此技能有两种模式,由连接器注入的凭据自动选择。先检查环境,然后按照匹配的部分操作:

  • 已设置 $DISCORD_USER_TOKEN → 用户令牌(BYOC)模式:通过 scripts/discord_user.py CLI 执行完整的个人账号操作(列出频道、读取消息、发送消息 / 回复)。这会以用户的真实账号执行操作。
  • 仅设置 $DISCORD_TOKEN → OAuth 模式:通过 curl 读取身份信息和服务器列表。此模式下无法访问频道消息。
if [ -n "$DISCORD_USER_TOKEN" ]; then echo "mode: user-token (full)"; \
elif [ -n "$DISCORD_TOKEN" ]; then echo "mode: oauth (read-only)"; \
else echo "no Discord connection — connect at https://studio.acedata.cloud/console/connectors"; fi

两个令牌都是**秘密信息,可访问完整账号。切勿回显或打印它们。**遇到 401 时,令牌已过期或被撤销——请告知用户前往 studio.acedata.cloud/console/connectors 重新连接。遇到 429 时,等待 retry_after 秒后重试;切勿并行执行。


用户令牌(BYOC)模式 — 完整操作

设置了 $DISCORD_USER_TOKEN 时,通过 CLI scripts/discord_user.py(使用 python3 运行)调用 discord.py-self,操作用户的真实账号。它仅使用令牌登录(不使用 gateway),并输出 JSON。

托管沙盒中已预装 discord.py-self(导入名称为 discord)。运行时不要执行 pip install;如果导入失败,请报告沙盒镜像缺少此依赖,然后停止。

**写入操作(send / reply)必须在末尾添加 --confirm 才能执行。**不添加时会进行试运行,并打印将要发送的内容。发送前,请与用户确认确切的频道和内容——此操作不可撤销且会公开显示。只有在用户批准后,才添加 --confirm(作为最后一个参数)。

# identity (always run first)
python3 scripts/discord_user.py whoami
# list the servers (guilds) the account is in
python3 scripts/discord_user.py guilds
# list text channels in a server
python3 scripts/discord_user.py channels --guild GUILD_ID
# read recent messages in a channel
python3 scripts/discord_user.py messages --channel CHANNEL_ID --limit 20
# send — dry-run first, then re-run with a trailing --confirm
python3 scripts/discord_user.py send --channel CHANNEL_ID --text "hello"
python3 scripts/discord_user.py send --channel CHANNEL_ID --text "hello" --confirm
# reply to a specific message
python3 scripts/discord_user.py reply \
  --channel CHANNEL_ID --message MESSAGE_ID --text "on it" --confirm

只有作为最后一个参数时(剥离一次),--confirm 才会生效,因此仅在消息正文中包含文本 --confirm,绝不会意外触发发送。ID 是数字形式的 Discord snowflake。如果沙盒需要代理才能访问 discord.com,可通过 DISCORD_PROXY 强制指定代理(否则会回退到 HTTPS_PROXY / ALL_PROXY)。


OAuth 模式 — 只读

仅设置了 $DISCORD_TOKEN 时,通过 curl + jq 调用 Discord API。 认证标头为 Authorization: Bearer $DISCORD_TOKEN;基础 URL 为 https://discord.com/api/v10。

作用域仅限只读的 identify + email + guilds。此模式只能读取账号身份信息及其服务器列表。它无法读取 / 发送频道消息、列出服务器的频道或成员,也无法管理任何内容——使用 OAuth 令牌时,/guilds/{id}/channels、/channels/...、/guilds/{id}/members 会返回 401/403。如果用户需要这些功能,必须通过用户令牌(上文的 BYOC 模式)连接 Discord,或使用 Discord Bot(discordbot 连接)以机器人身份操作。

# identity (always run first)
curl -sS -H "Authorization: Bearer $DISCORD_TOKEN" \
  "https://discord.com/api/v10/users/@me" \
  | jq '{id, username, global_name, email, avatar}'

# the servers (guilds) the user is in (add ?with_counts=true for member counts)
curl -sS -H "Authorization: Bearer $DISCORD_TOKEN" \
  "https://discord.com/api/v10/users/@me/guilds?with_counts=true" \
  | jq 'map({id, name, owner, members: .approximate_member_count})'

备注

  • UI 中的“服务器”在 API 中称为“guild”;消息位于 guild 中的频道内。用户令牌模式下:guilds → channels --guild <id> → 对频道 ID 执行操作。不要编造 ID。
  • OAuth 模式下,owner: true 表示用户拥有该 guild。guild 图标 URL(当 icon 非 null 时):https://cdn.discordapp.com/icons/<guild_id>/<icon>.png(如果哈希以 a_ 开头,则使用 .gif)。guild 列表每页最多返回 200 个;如果达到上限,请使用 ?after=<last_guild_id> 翻页。

评论

支持 Markdown