discli
CLAUDE.md35 starsChanged 9 months agoMITView on GitHub
discli is a Discord CLI for AI agents and humans — a Python command-line tool for managing Discord servers, messages, reactions, threads, DMs, events, voice audio, and rich interactive components (modals, workflows, dashboards) from the terminal. Published on PyPI as discord-cli-agent. This project uses uv for dependency management. No linter is configured. Commit style: conventional commits (feat:, fix:, docs:, chore:). There is no pytest config, and asyncio_mode is unset, so async tests need explicit @pytest.mark.asyncio. tests/conftest.py holds one autouse fixture,…
- Reads credentials
- Commits and pushes
In this repository7 other files it gives its agents.
- discord-agentSkill
- discord-botSkill
- discord-loggerSkill
- discord-moderationSkill
- discord-slash-commandsSkill
- discord-support-botSkill
- discord-welcomeSkill
The file
We split this CLAUDE.md into the rules it gives an agent
5 rules. About 0 are common, 0 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 33
No linter is configured. Commit style: conventional commits (feat:, fix:, docs:, chore:).
- Very specific: line 99
Create file in src/discli/commands/
- Very specific: line 102
Add tests in tests/
- Very specific: line 103
Update agents/discord-agent.md with command reference
- Very specific: line 104
Update the relevant skills/*/SKILL.md if the command appears there (7 skills ship in skills/)
≈ “Common” is an estimate: at least 1 in 5 of the 29,248 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
discli is a Discord CLI for AI agents and humans — a Python command-line tool for managing Discord servers, messages, reactions, threads, DMs, events, voice audio, and rich interactive components (modals, workflows, dashboards) from the terminal. Published on PyPI as discord-cli-agent.
Commands
This project uses uv for dependency management.
# Install (editable, with dev deps) — creates .venv/ automatically
uv sync --dev
# Install with voice features (TTS/STT providers)
uv sync --dev --extra voice --extra elevenlabs --extra deepgram
# Run tests
uv run pytest tests/ -v
# Run a single test
uv run pytest tests/test_utils.py -v
# Run the CLI
uv run discli --help
# Build package
uv buildNo linter is configured. Commit style: conventional commits (feat:, fix:, docs:, chore:).
There is no pytest config, and asyncio_mode is unset, so async tests need explicit @pytest.mark.asyncio. tests/conftest.py holds one autouse fixture, no_network, which patches discord.http.HTTPClient.request/static_login to raise — without it a test that drives the CLI end to end falls back to the developer's own token in ~/.discli/config.json and makes live API calls that pass locally and fail in CI. tests/test_examples.py imports and executes every file in examples/, so a broken example breaks the suite.
Environment Variables
DISCORD_BOT_TOKEN— bot token (Clickenvvar, also read byclient.py)DISCLI_TTS/DISCLI_STT/DISCLI_TTS_VOICE— provider selectionDISCLI_DEEPGRAM_MODEL(defaultnova-3),DISCLI_DEEPGRAM_LANGUAGE(defaultmulti)ELEVENLABS_API_KEY,DEEPGRAM_API_KEY,OPENAI_API_KEY— provider credentials
Note: examples/meeting_transcriber.py reads DISCORD_TOKEN, not DISCORD_BOT_TOKEN.
Gotchas
discord-ext-voice-recv==0.5.2a179is an exact pin — do not bump. See the justification comment inpyproject.toml(0.4.x lacks the required cipher; 0.5.0a167 has a circular import; 0.5.1a170 doesn't deliver audio).- Voice requires ffmpeg on PATH and the DAVE encryption patch. Run
discli doctorfirst when voice misbehaves. audioop-ltsis a conditional dep for Python ≥3.13 (stdlibaudioopremoval).- Intents are only sent on the Gateway path (
listen,serve,voice). One-shot commands userun_rest()and transmit no intents. Missing privileged intents fail the whole Gateway connection (PrivilegedIntentsRequired) but only fail individual REST calls with a 403. run_rest_action()setsIntents.members = Trueon the login-only client. That flag never reaches Discord — it exists to defeat discord.py's client-side guard inGuild.fetch_members(), which raisesClientException(a sibling ofHTTPException, so no handler catches it) before any request goes out. Do not "clean this up" toIntents.none().- Channel listings are scoped to what the bot can view, and from 2026-11-16 Discord drops channels without
VIEW_CHANNELfromGET /guilds/{id}/channelsand the Gateway entirely. No API reports how many were withheld.channel listandserver infodisclose this viawarn_channel_visibility()on stderr — deliberately not stdout, so--jsonpayloads stay parseable.serve'schannel_listsetsvisible_only: truein-band instead, because JSONL has no stderr equivalent. - Discord split
PIN_MESSAGES,BYPASS_SLOWMODE,CREATE_GUILD_EXPRESSIONS, andCREATE_EVENTSout of broader permissions during 2026. A bot invited before the split keeps the old bit and silently loses the new capability.discli doctor --server <name>detects exactly that case (holds legacy bit, lacks split bit); seePERMISSION_SPLITSincommands/doctor.py. message search-servercallsGET /guilds/{id}/messages/searchthrough a rawdiscord.http.Route, because discord.py 2.7.1 does not wrap that endpoint. Going throughRoutekeeps it inside discord.py's rate limiter and auth. Discord answers 202 with nomessageskey while it is still indexing a guild — treating that as an empty result set would report a wrong answer rather than a slow one.scheduleactions are discli command lines, never shell commands.parse_action()lexes withshlex(punctuation_chars=True)so;and&&become their own tokens, then walks the real Click tree. Backticks and$are deliberately not rejected — no shell is involved, and a message containing backtick-wrapped code formatting is ordinary Discord content.- Scheduled actions run via
asyncio.to_thread: discli commands callasyncio.run()internally, which raises if invoked from the scheduler's own running event loop. tzdatais a Windows-only conditional dep. Windows ships no IANA tz database, soschedule --tzwould otherwise raiseZoneInfoNotFoundError.server applyis additive by default: it creates and updates what the spec names and leaves everything else alone. Deletions require--prune, which routes throughconfirm_destructive. Spec items are matched by name, not ID, so a rename reads as delete-plus-create — that is the price of a spec being portable between servers._compare()inserver_spec.pyonly diffs fields the spec actually declares. An omitted field means "not managed here", not "set to null" — otherwise a hand-trimmed spec would blank out everything it left out.- Channel/role positions are exported but never applied. Discord renumbers siblings on every positional write, so applying them produces churn and ordering that depends on apply order.
- Dashboard pages may set
layout: "v2"for Components v2, but every page of one dashboard must use the same layout. Discord stampsIS_COMPONENTS_V2on the message at send time and it cannot be toggled, so paging between an embed page and a v2 page is impossible;DashboardDefinition.__post_init__rejects the mix. A v2 message also carries no content or embeds. - v2 buttons keep the same
dash:<id>:<key>custom_id prefix as the embed layout, so interaction routing is identical across both. - The
moderationpermission profile is an allowlist, not["*"]. It used to be byte-identical tofull, which made selecting it for least privilege a no-op. Voice and interact are in scope on purpose (commitdf6b606) and must stay;permission setmust stay out or the profile can promote itself tofull.tests/test_permission_profiles.pypins both, plus the moderation-is-a-superset-of-readonly invariant. - The permission profile is enforced in
run_rest()/run_gateway(), so a command that never calls Discord skips it entirely. Local commands (permission set,audit clear,config set,schedule *,serve,listen) must callenforce_profile(ctx)themselves.test_no_command_silently_skips_the_permission_checkfails if a new one forgets. resolve_guild()by name goes throughGET /users/@me/guilds, which returns partial guilds with no roles and noowner_id. Anything readingMember.guild_permissionsorguild.get_role()off one computes zero instead of failing, so_ensure_full_guild()re-fetches by ID. Do not remove it.fetch_channels()does not populate the guild's channel cache either, sochannel.categoryis always None on a REST client.server_spec._channel_spec()resolves the parent fromcategory_idagainst the fetched list instead.cli.pyreconfigures stdout/stderr to UTF-8 at startup. Windows consoles and redirected pipes default to a legacy code page, and emoji in Discord channel names would otherwise raiseUnicodeEncodeError.- Profile patterns match by prefix, so a bare group name in an
allowedlist grants every command that group will ever have.chatlisted"config"and"server", which is how it came to allowconfig set(overwriting the stored token) andserver apply. Spell out subcommands unless blanket access is intended;test_no_profile_grants_a_whole_group_by_bare_prefixenforces it against the live tree. confirm_destructive()callsenforce_profile()before prompting. Otherwise a forbidden command asks "are you sure?" and only refuses after you say yes.
Architecture
Entry point: src/discli/cli.py → Click root group → registers all command groups.
Core flow: Click CLI → permission/audit check (security.py) → run_rest() for one-shot HTTP actions or run_gateway() for live state → async discord.py action → output() (utils.py).
Key modules:
client.py— Token resolution, REST/Gateway lifecycle separation, and minimal Gateway intent constructionsecurity.py— Permission profiles (full/chat/readonly/moderation), audit logging to~/.discli/audit.log(JSONL), token-bucket rate limiterutils.py— Output formatting plus async, cache-first resource resolvers with REST fallbacksconfig.py— Token storage at~/.discli/config.jsonvoice_engine.py— VoiceEngine with AudioPlayer, AudioListener, VAD-based speech segmentation, audio codec handlinginteract_engine.py— InteractEngine for modals, workflows, and dashboards with interaction routing and state management; also the Components v2 block builders (build_v2_block,build_v2_view)tts.py— TTS provider protocol with ElevenLabs and OpenAI implementationsstt.py— STT provider protocol with Deepgram and OpenAI Whisper implementationscommands/server_spec.py—server export/diff/apply; decoratesserver_groupfromserver.py, which imports it at the bottom for that side effectcommands/schedule.py—discli schedule, recurring discli commands stored in~/.discli/schedules.json;schedule rundrives them withdiscord.ext.taskscommands/doctor.py—discli doctor, the first-stop diagnostic: checks token, ffmpeg on PATH, DAVE/Opus voice patches, provider API keys. All local unless--serveris passed, which adds the network permission-bitfield check
The permission and audit command groups are defined inline in cli.py, not in commands/.
Command pattern: Each module in commands/ defines Click commands and an async action. One-shot commands call run_rest(ctx, action). Only live events, voice state, and persistent connections call run_gateway(ctx, action, features=...) or manage a long-lived Gateway client directly.
serve command (commands/serve.py): The largest module (~2100 lines). Runs a persistent bot with bidirectional JSONL over stdin/stdout. Features: event forwarding, action dispatch (send/reply/edit/delete/stream/typing/reactions/threads/polls/channels/members/roles/DMs), voice actions (connect/speak/play/listen/etc.), interactive actions (workflows, dashboards), slash command registration, streaming message edits with periodic flush, Windows-compatible stdin reading via threading.
Adding a New Command
- Create file in
src/discli/commands/ - Define Click group/command following existing patterns
- Register in
src/discli/cli.py - Add tests in
tests/ - Update
agents/discord-agent.mdwith command reference - Update the relevant
skills/*/SKILL.mdif the command appears there (7 skills ship inskills/)
Docs Development
# Start docs dev server (Lito, Astro-based)
npx @litodocs/cli dev -i ./docs
# Build docs for production
npx @litodocs/cli build -i ./docs -o ./docs/distDocs live in docs/ — Lito framework with docs-config.json for sidebar/theme. Custom landing page in docs/_landing/.
Release Process
Bump version in pyproject.toml → commit → git tag vX.Y.Z && git push origin vX.Y.Z → CI runs tests (Python 3.10–3.13), builds, creates GitHub Release, publishes to PyPI.
There is no CI on pushes or PRs — tests run only on v* tags, so run uv run pytest tests/ -v locally before pushing. The docs workflow is path-filtered to docs/** on main.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

