GoForum🌐 V2EX

做了一个 discord-cli :把 discord 变成可本地检索、可供 AI Agent 使用的数据层

jakevin · 2026-03-13 15:43 · 0 次点赞 · 0 条回复

[分享] discord-cli — 把 Discord 聊天记录同步到本地 SQLite ,终端搜索 + AI 总结

项目背景

平时泡不少 Discord 社区( crypto 、开源项目、AI 讨论组),消息量大、翻找困难。Discord 自带搜索不支持正则,也没法离线查看。于是写了 discord-cli——一个 local-first 的 Discord 命令行工具:

  • 把频道消息增量同步到本地 SQLite
  • 终端里全文检索、统计、导出
  • 可选接 Claude 做频道摘要 / 分析

GitHub: https://github.com/jackwener/discord-cli

PyPI: https://pypi.org/project/kabi-discord-cli/

核心功能

1. 一键同步聊天记录

# 提取并保存本地 Discord token
discord auth --save

# 发现所有可见文字频道并同步
discord dc sync-all -n 500

# 增量同步(只拉新消息)
discord dc sync-all
  • 自动处理 Discord rate limit (读 retry_after / X-RateLimit-Remaining header ,不会触发封号)
  • 消息存入 ~/Library/Application Support/discord-cli/messages.db

2. 本地搜索 & 统计

# 全文搜索
discord search "rust" -c general

# 今天的消息
discord today

# 按小时统计活跃度
discord timeline --by hour

# 谁发言最多
discord top --hours 24

# 各频道消息量
discord stats

3. 结构化输出,方便脚本 / AI Agent

# JSON / YAML 输出
discord search "release" --json
discord today -c general --yaml

# 导出为文件
discord export general -f json -o out.json
  • 非 TTY 环境自动输出 YAML
  • 所有输出遵循统一的 envelope schema

4. AI 总结 & 分析(可选)

# 安装 AI 依赖
uv tool install 'kabi-discord-cli[ai]'
export ANTHROPIC_API_KEY=...

# 频道 AI 分析
discord analyze general --hours 24

# 全局摘要
discord summary --hours 12

安装

# 推荐
uv tool install kabi-discord-cli

# 或 pipx
pipx install kabi-discord-cli

Python 3.10+ 即可,依赖很少( httpx + click + rich + PyYAML )。

典型使用场景

  1. 信息归档:把重要 Discord 社区的讨论同步到本地,不怕频道被删或服务器跑路
  2. 快速检索:在终端快速搜索历史消息,比 Discord 自带搜索灵活
  3. 每日摘要:用 discord summary 生成 AI 摘要,快速了解今天社区讨论了什么
  4. 数据分析timeline / top / stats 了解社区活跃度
  5. AI Agent 集成:附带 SKILL.md ,可以被 Claude Code / Antigravity 等 AI agent 直接调用

同系列工具

这是我做的社交平台 CLI 系列的一部分,同样的 local-first 思路:

工具 平台 GitHub
twitter-cli Twitter/X https://github.com/jackwener/twitter-cli
bilibili-cli 哔哩哔哩 https://github.com/jackwener/bilibili-cli
xiaohongshu-cli 小红书 https://github.com/jackwener/xiaohongshu-cli
tg-cli Telegram https://github.com/jackwener/tg-cli

Apache-2.0 开源,欢迎 Star ⭐ 和反馈 🙏

有什么想法或者需要支持的功能,欢迎在 Issues 里提。

0 条回复
添加回复
你还需要 登录 后发表回复

登录后可发帖和回复

登录 注册
主题信息
作者: jakevin
发布: 2026-03-13
点赞: 0
回复: 0