@@ -41,15 +41,13 @@ graph TD
4141
4242``` mermaid
4343graph LR
44- A[discli listen --json] --> B[Events\nJSONL stream]
45- B --> C[AI Agent\ne.g. Claude]
46- C --> D[discli message reply]
47- D --> E[Discord]
48- A --> E
44+ A[discli serve] -->|stdout JSONL| B[AI Agent\ne.g. Claude]
45+ B -->|stdin JSONL| A
46+ A <-->|persistent| C[Discord Bot API]
4947
5048 style A fill:#5865F2,color:#fff
51- style C fill:#D97706,color:#fff
52- style E fill:#5865F2,color:#fff
49+ style B fill:#D97706,color:#fff
50+ style C fill:#5865F2,color:#fff
5351```
5452
5553``` mermaid
@@ -229,6 +227,49 @@ discli --json listen --events messages
229227
230228Supported event types: ` messages ` , ` reactions ` , ` members ` , ` edits ` , ` deletes `
231229
230+ ### Persistent Bot (serve)
231+
232+ ` discli serve ` keeps a persistent connection and communicates via stdin/stdout JSONL — ideal for building full Discord bots.
233+
234+ ``` bash
235+ # Start with slash commands and presence
236+ discli serve --slash-commands commands.json --status online --activity playing --activity-text " Helping"
237+
238+ # Filter by server
239+ discli serve --server " My Server"
240+ ```
241+
242+ ** Events (stdout):**
243+ ``` json
244+ {"event" : " ready" , "bot_id" : " 123" , "bot_name" : " MyBot#1234" }
245+ {"event" : " message" , "channel_id" : " 456" , "author" : " alice" , "content" : " hello" , "mentions_bot" : true , ... }
246+ {"event" : " slash_command" , "command" : " paw" , "args" : {"message" : " hi" }, "interaction_token" : " abc123" , ... }
247+ ```
248+
249+ ** Commands (stdin):**
250+ ``` json
251+ {"action" : " send" , "channel_id" : " 456" , "content" : " Hello!" , "req_id" : " 1" }
252+ {"action" : " reply" , "channel_id" : " 456" , "message_id" : " 789" , "content" : " Hi!" , "req_id" : " 2" }
253+ {"action" : " typing_start" , "channel_id" : " 456" }
254+ {"action" : " typing_stop" , "channel_id" : " 456" }
255+ {"action" : " presence" , "status" : " idle" , "activity_type" : " watching" , "activity_text" : " the logs" }
256+ ```
257+
258+ ** Streaming edits** (bot response builds in real-time, edited every 1.5s):
259+ ``` json
260+ {"action" : " stream_start" , "channel_id" : " 456" , "reply_to" : " 789" }
261+ {"action" : " stream_chunk" , "stream_id" : " s1" , "content" : " new tokens..." }
262+ {"action" : " stream_end" , "stream_id" : " s1" }
263+ ```
264+
265+ ** Slash commands** are defined in a JSON file:
266+ ``` json
267+ [
268+ {"name" : " paw" , "description" : " Talk to the bot" , "params" : [{"name" : " message" , "type" : " string" }]},
269+ {"name" : " new" , "description" : " Start a new session" }
270+ ]
271+ ```
272+
232273## Security & Permissions
233274
234275### Confirmation Prompts
@@ -251,11 +292,15 @@ Restrict which commands an agent can use:
251292# List available profiles
252293discli permission profiles
253294
254- # Set a profile
295+ # Set a profile (persisted)
255296discli permission set chat # Messages, reactions, threads only, no moderation
256297discli permission set readonly # Can only read, no sending or deleting
257298discli permission set moderation # Full access including kick/ban
258299discli permission set full # Everything (default)
300+
301+ # Override per invocation (not persisted)
302+ discli --profile chat message send # general "hello"
303+ DISCLI_PROFILE=readonly discli message list # general
259304```
260305
261306| Profile | Can Send | Can Delete | Can Kick/Ban | Can Manage Channels |
@@ -334,6 +379,7 @@ Ready-to-run examples in the [`examples/`](examples/) directory:
334379
335380| Example | Description |
336381| ---------| -------------|
382+ | [ ` serve_bot.py ` ] ( examples/serve_bot.py ) | Full bot using ` discli serve ` with streaming responses and slash commands |
337383| [ ` claude_agent.py ` ] ( examples/claude_agent.py ) | AI support agent powered by Claude Agent SDK with persistent session |
338384| [ ` support_agent.py ` ] ( examples/support_agent.py ) | Keyword-based support bot that replies to @mentions |
339385| [ ` thread_support_agent.py ` ] ( examples/thread_support_agent.py ) | Creates a thread per support request and continues conversations inside |
@@ -379,7 +425,7 @@ discli/
379425│ ├── config.py # Token storage (~/.discli/config.json)
380426│ ├── security.py # Permissions, audit logging, rate limiting
381427│ ├── utils.py # Output formatting, resolvers
382- │ └── commands/ # Command groups (message, channel, role , etc.)
428+ │ └── commands/ # Command groups (message, channel, serve , etc.)
383429├── agents/
384430│ └── discord-agent.md # Full command reference for AI agents
385431├── examples/ # Ready-to-run agent examples
0 commit comments