discli 讓你在命令列完整控制 Discord。預設輸出為人類易讀文字;加上 --json 則輸出結構化資料,便於腳本處理與導流。
實體名稱解析
先確認 discli 對 Discord 實體的解析方式:
| 前綴 | 解析目標 | 範例 |
|---|---|---|
# | 依名稱解析頻道 | #general |
@ | 依名稱解析使用者 | @alice |
| 純數字 | 依 ID 解析任意實體 | 1234567890 |
| 一般字串 | 依名稱解析伺服器 | "My Server" |
Tip
含 # 的頻道名稱與含 @ 的使用者名稱,會在機器人可見的所有伺服器中做不分大小寫比對。若名稱重複,請改用 ID。
傳送訊息
最常見操作。可以對機器人可存取的任意頻道傳訊息:
discli message send "#general" "Hello from the terminal!"discli message send 1234567890 "Deploy complete. All systems green."discli message send "#logs" "Here's today's report" --file ./report.csvdiscli message send "#announcements" "New release!" \ --embed-title "v2.1.0" \ --embed-desc "Bug fixes and performance improvements"discli message send "#announcements" "Check this out" \ --embed-title "Status Update" \ --embed-color 5865F2 \ --embed-footer "Last updated today" \ --embed-field "Service::Operational::true"讀取訊息
抓取近期訊息、依內容搜尋,或用 ID 取單筆訊息。
# 預設顯示最近 10 筆discli message list "#general"
# 最近 50 筆discli message list "#general" --limit 50
# 取得特定時間之前訊息discli message list "#general" --before 2025-01-15
# 取得特定時間之後訊息discli message list "#general" --after 2025-01-01# 依內容搜尋discli message search "#support" "payment failed"
# 依內容與作者搜尋discli message search "#support" "refund" --author "alice#1234"
# 指定時間區間搜尋discli message search "#general" "deploy" --after 2025-03-01 --limit 200# 以 ID 取得特定訊息discli message get "#general" 1234567890123456# 最近 7 天discli message history "#general" --days 7
# 最近 2 小時discli message history "#general" --hours 2
# 最近 7 天,最多 500 筆discli message history "#general" --days 7 --limit 500JSON 輸出與 jq 管線
任一指令加上 --json 後會回傳 JSON 結構,適合做腳本串接。
# 取得 JSON 輸出discli --json message list "#general" --limit 5[ { "id": "1234567890", "author": "alice#1234", "content": "Hello everyone!", "timestamp": "2025-03-15T10:30:00", "attachments": [], "embeds": [] }]可用 jq 做過濾與轉換:
discli --json message list "#general" --limit 20 | jq '.[].content'discli --json message list "#general" --limit 100 \ | jq '[.[] | select(.attachments | length > 0)]'discli --json message list "#general" --limit 100 \ | jq '[.[].author] | unique'discli --json message list "#general" --limit 100 \ | jq 'group_by(.author) | map({author: .[0].author, count: length}) | sort_by(-.count)'discli --json message list "#general" --limit 100 \ | jq -r '.[] | [.timestamp, .author, .content] | @csv' > messages.csv回覆與編輯
# 回覆指定訊息discli message reply "#general" 1234567890123456 "Thanks for the update!"
# 編輯訊息(必須是機器人自己的)discli message edit "#general" 1234567890123456 "Updated content here"
# 刪除訊息(需要確認)discli message delete "#general" 1234567890123456
# 一次刪除多則訊息discli -y message bulk-delete "#general" 111 222 333Warning
像 message delete 這類高風險指令會先要求確認。腳本場景可加 --yes 或 -y:discli --yes message delete "#general" 1234567890。
頻道管理
# 所有伺服器的頻道discli channel list
# 指定伺服器頻道discli channel list --server "My Server"
# JSON 腳本用途discli --json channel list --server "My Server" | jq '.[] | select(.type == "text")'# 建立文字頻道discli channel create "My Server" "new-channel"
# 建立語音頻道discli channel create "My Server" "voice-room" --type voice
# 建立分類discli channel create "My Server" "Project Alpha" --type category
# 建立論壇頻道discli channel create "My Server" "feedback" --type forum --topic "Share your feedback"
# 建立論壇貼文discli channel forum-post "#feedback" "Feature Request" "Add dark mode support"# 編輯頻道主題與慢速模式discli channel edit "#general" --topic "New topic" --slowmode 10# 設定頻道權限(角色)discli channel set-permissions "#general" "Members" \ --allow send_messages \ --deny manage_messages# 取得頻道詳情discli channel info "#general"
# JSON 輸出discli --json channel info "#general"輸出會包含:ID、名稱、類型、伺服器、主題與建立日期。
# 刪除頻道(需要確認)discli channel delete "#old-channel"
# 跳過確認discli --yes channel delete "#old-channel"成員操作
# 列出伺服器成員discli member list "My Server"discli member list "My Server" --limit 100
# 取得成員明細(角色、加入時間等)discli member info "My Server" "@alice"discli member info "My Server" 1234567890
# 踢除成員(需確認)discli member kick "My Server" "@spammer" --reason "Spam"
# 封鎖成員discli member ban "My Server" "@troll" --reason "Repeated violations"
# 解除封鎖discli member unban "My Server" "@reformed"
# 將成員禁言 1 小時(3600 秒)discli -y member timeout "My Server" "@spammer" 3600 --reason "Spam"
# 解除禁言(duration 設 0)discli -y member timeout "My Server" "@spammer" 0--triggered-by 旗標
當機器人代替 Discord 使用者執行動作時,請傳使用者 ID,讓 discli 驗證該使用者在伺服器中的必要權限:
discli member kick "My Server" "@spammer" \ --reason "Spam" \ --triggered-by 9876543210此時會先檢查 9876543210 是否具備 kick_members 權限。檢查結果會寫進稽核紀錄。
反應
# 新增反應discli reaction add "#general" 1234567890123456 "👍"
# 移除機器人反應discli reaction remove "#general" 1234567890123456 "👍"
# 列出訊息上的反應discli reaction list "#general" 1234567890123456
# 列出對特定 emoji 反應的使用者discli reaction users "#general" 1234567890123456 "👍"Note
Unicode emoji 可直接使用。自定義伺服器 emoji 請用 <:name:id>,或機器人已可見時直接用表情名稱。
私訊
# 向使用者發 DMdiscli dm send "@alice" "Your report is ready!"discli dm send 1234567890 "Your report is ready!"
# 列出與某位使用者的近期 DMdiscli dm list "@alice"discli dm list "@alice" --limit 20討論串
# 從訊息建立討論串discli thread create "#general" 1234567890123456 "Discussion Thread"
# 列出頻道中啟用的討論串discli thread list "#general"
# 發訊息到討論串discli thread send 9876543210 "Replying in the thread"
# 附件傳送discli thread send 9876543210 "Here's the file" --file ./data.json
# 封存 / 解除封存discli thread archive 9876543210discli thread unarchive 9876543210
# 重新命名discli thread rename 9876543210 "New Thread Name"
# 新增或移除討論串成員discli thread add-member 9876543210 "@alice"discli thread remove-member 9876543210 "@alice"身分組
# 列出伺服器身分組discli role list "My Server"
# 建立身分組discli role create "My Server" "Contributor" --color "00ff00"
# 指派身分組discli role assign "My Server" "@alice" "Contributor"
# 移除身分組discli role remove "My Server" "@alice" "Contributor"
# 編輯身分組discli role edit "My Server" "Contributor" \ --name "Core Contributor" \ --color 00ff00 \ --hoist \ --mentionable
# 刪除身分組(需確認)discli role delete "My Server" "OldRole"伺服器操作
# 列出機器人所在伺服器discli server list
# 取得伺服器詳細資料discli server info "My Server"
# JSON 腳本用途discli --json server list | jq '.[] | {name, member_count}'投票
# 建立投票(透過 serve 模式)# 詳細參數請參閱 Serve 模式文件
# 查詢投票結果discli poll results "#general" 1234567890123456
# 提前結束投票discli poll end "#general" 1234567890123456Webhooks
# 列出頻道 webhookdiscli webhook list "#general"
# 建立 webhookdiscli webhook create "#general" "Deploy Notifier"
# 刪除 webhook(需確認)discli -y webhook delete "#general" 9876543210排程事件
# 列出伺服器排程事件discli event list "My Server"
# 建立排程事件discli event create "My Server" "Game Night" \ --start "2026-04-01T20:00:00" \ --end "2026-04-01T23:00:00" \ --description "Weekly game night"
# 刪除排程事件(需確認)discli -y event delete "My Server" 9876543210權限設定檔
限制機器人的可執行範圍:
# 顯示目前設定檔discli permission show
# 列出可用設定檔discli permission profiles
# 切換到限制較高的設定檔discli permission set readonly
# 指令層級覆蓋discli --profile chat message send "#general" "Hello"完整限制內容請參考 安全與權限。
稽核紀錄
檢視已執行的高風險操作:
# 顯示最近紀錄discli audit showdiscli audit show --limit 50
# JSON 輸出discli --json audit show --limit 10
# 清空紀錄discli audit clear常用模式
快速狀態檢查
# 某頻道活躍度discli --json message list "#general" --limit 100 \ | jq 'length'搜尋某位使用者訊息
discli --json message search "#general" "" --author "alice#1234" --limit 100 \ | jq 'length'廣播到多個頻道
for channel in "#announcements" "#general" "#dev"; do discli message send "$channel" "Server maintenance at 2 AM UTC tonight."done匯出頻道歷史
discli --json message history "#general" --days 30 \ | jq -r '.[] | [.timestamp, .author, .content] | @csv' \ > general-export.csv全域旗標參考
| 旗標 | 短版 | 說明 |
|---|---|---|
--token | 指定 bot token(優先權高於 env 與 config) | |
--json | 以結構化 JSON 輸出 | |
--yes | -y | 跳過高風險操作確認 |
--profile | 覆寫權限設定檔(full、chat、readonly、moderation) |