使用官方 Claude Code Channels Discord 插件,將 Claude Code session 與 Discord Bot 串接,實現雙向溝通。架構與 Telegram 相同:outbound 連線,不需要開 inbound port。
架構概覽:
Discord App (桌面/手機/網頁)
| (WebSocket Gateway, plugin 主動連線)
Discord Plugin (Bun subprocess, MCP Server)
| (stdio transport)
Claude Code Session (本地,有完整檔案系統存取)
- Bun runtime(已為 Telegram 安裝)
- Claude Code v2.1.80+(v2.1.81)
- Discord Bot Token(從 Discord Developer Portal 取得)
- Discord Bot 已加入目標伺服器並設定正確權限
- 前往 Discord Developer Portal
- 點擊 New Application,命名
- 進入 Bot 區段:
- 建立 username
- 點擊 Reset Token 並複製(僅顯示一次)
- 啟用 Message Content Intent(位於 Privileged Gateway Intents)
- 進入 OAuth2 > URL Generator:
- Scope:
bot - 權限:
- View Channels
- Send Messages
- Send Messages in Threads
- Read Message History
- Attach Files
- Add Reactions
- Integration type: Guild Install
- Scope:
- 開啟產生的 URL,將 Bot 加入你的伺服器
在 Claude Code session 內執行:
/plugin install discord@claude-plugins-official
/discord:configure <DISCORD_BOT_TOKEN>
Token 儲存於專案層級:.claude/channels/discord/.env
./start.sh discord
# 或同時啟動兩個 channel:
./start.sh telegram discord-
在 Discord 私訊你的 Bot
-
Bot 回覆 配對碼
-
在 Claude Code terminal 輸入:
/discord:access pair <CODE> -
鎖定存取:
/discord:access policy allowlist
- 基本測試:私訊 Bot,確認 Claude Code 收到並回覆
- 伺服器頻道:以頻道 ID 加入(opt-in)一個伺服器頻道
- 審批流程:透過 Discord 測試 approve/reject 模式
- 附件測試:發送檔案,確認
download_attachment正常運作
| 工具 | 說明 |
|---|---|
reply |
發送訊息(chat_id + text,可選 reply_to 串接回覆、files 附件,最多 10 檔/25MB) |
react |
添加 emoji 回應(unicode 或自訂 <:name:id> 格式) |
edit_message |
編輯 Bot 先前發送的訊息 |
fetch_messages |
取得最近 100 則訊息(由舊到新,含 message ID) |
download_attachment |
下載訊息中的附件到 inbox/ |
注意: Discord plugin 有 fetch_messages(Telegram 沒有),可讀取頻道歷史訊息。
| 面向 | Telegram | Discord |
|---|---|---|
| 連線方式 | HTTP long-polling | WebSocket Gateway |
| 訊息歷史 | 不可用 | fetch_messages(最多 100 則) |
| 附件處理 | 自動下載 | 需明確呼叫 download_attachment |
| ID 格式 | 數字 chat_id | Snowflake ID(數字) |
| 群組存取 | 透過白名單 | 以頻道 ID 逐一 opt-in |
| 檔案限制 | 每檔 50MB | 每檔 25MB,最多 10 檔 |
在 .claude/settings.local.json 中加入:
{
"permissions": {
"allow": [
"mcp__plugin_discord_discord__reply"
]
}
}| 檔案 | 用途 |
|---|---|
.claude/channels/discord/.env |
DISCORD_BOT_TOKEN(gitignored) |
.claude/channels/discord/access.json |
存取控制與白名單(gitignored) |
.claude/channels/discord/inbox/ |
下載的附件(gitignored) |
docs/discord/plan.md |
本計畫文件(英文版) |
docs/discord/install.md |
安裝筆記(待建立) |