Architecture
The Discord adapter (magpie-discord) is built with Serenity, a Rust library for the Discord API. When a user @mentions the bot, it:
Creates a thread from the triggering message
Thread names are formatted as
magpie: <task> and auto-truncate at 100 characters (Discord’s limit) while respecting word boundaries.Runs the pipeline in the background
Executes the full autonomous coding workflow (branch creation, agent work, CI, PR).
Setup
1. Create a Discord Bot
Navigate to the Discord Developer Portal
Go to discord.com/developers/applications and create a new application.
Configure Gateway Intents
Enable these privileged intents:
GUILD_MESSAGES— receive message events in serversMESSAGE_CONTENT— read message content for task parsingGUILDS— access server metadata
2. Invite the Bot to Your Server
Generate an OAuth2 invite URL with these scopes and permissions:- Scopes:
bot - Permissions:
- Read Messages/View Channels
- Send Messages
- Send Messages in Threads
- Create Public Threads
- Manage Threads
3. Configure Environment Variables
Create a.env file or set environment variables:
.env
4. Run the Bot
Usage
Mention the bot in any channel with a task description:- Create a thread named
magpie: add a health check endpoint to the API - Acknowledge the task in the thread
- Run the pipeline (you’ll see progress in logs)
- Post the final result with PR link
- Archive and lock the thread
Thread Behavior
Auto-Archiving
Magpie automatically archives and locks threads after posting the final pipeline result. This is implemented via theclose_thread() method in ChatPlatform:
crates/magpie-discord/src/adapter.rs:46-56
Thread Name Truncation
Discord limits thread names to 100 characters. Magpie intelligently truncates long task descriptions:- Preserves the
magpie:prefix - Breaks at word boundaries (not mid-word)
- Appends
...when truncated - Handles Unicode/emoji correctly
Fallback to Channel
If thread creation fails (e.g., missing permissions), Magpie falls back to posting directly in the channel:crates/magpie-discord/src/handler.rs:52-71
Mention Handling
Magpie strips Discord @mention syntax from task text:crates/magpie-discord/src/handler.rs:165-173
<@123456> (standard) and <@!123456> (nickname) mentions are supported.
Deployment Patterns
Systemd Service
/etc/systemd/system/magpie-discord.service
Docker Compose
docker-compose.yml
Kubernetes Deployment
magpie-discord.yaml
Monitoring & Debugging
Logging
Magpie usestracing for structured logging. Control verbosity with RUST_LOG:
Health Checks
The Discord adapter doesn’t expose an HTTP health endpoint. Monitor bot status via:- Discord presence: Online/offline status in server member list
- Logs:
magpie-discord connected as ...on startup - Test mention: Send a simple task and verify acknowledgment
Common Issues
Bot doesn't respond to mentions
Bot doesn't respond to mentions
Check permissions:Look for “Ignoring bot message” or “No mention detected” warnings.
- Verify
MESSAGE_CONTENTintent is enabled in Developer Portal - Confirm bot has “View Channel” and “Send Messages” permissions
Thread creation fails
Thread creation fails
Missing permissions: Bot needs “Create Public Threads” and “Manage Threads”Fallback behavior: Magpie will post to the original channel if thread creation fails. Check logs for:
Pipeline errors not reported to Discord
Pipeline errors not reported to Discord
Check send_message fallback: If the platform send fails, Magpie attempts a direct channel send:Check logs for “failed to send result via platform” or “fallback send also failed”.
crates/magpie-discord/src/handler.rs:101-110
Bot crashes on startup
Bot crashes on startup
Invalid token: Verify Network issues: Check firewall/proxy settings for Discord Gateway access (wss://gateway.discord.gg)Serenity version conflicts: Rebuild with clean dependencies:
DISCORD_TOKEN is correctImplementation Reference
The Discord adapter implements theChatPlatform trait from magpie-core:
crates/magpie-discord/src/adapter.rs:22-57
Source Files
crates/magpie-discord/src/main.rs— Entry point, client setupcrates/magpie-discord/src/adapter.rs—ChatPlatformimplementationcrates/magpie-discord/src/handler.rs— Serenity event handler, thread managementcrates/magpie-discord/src/reply.rs— Pipeline result formatting
Next Steps
Teams Adapter
Deploy Magpie to Microsoft Teams with Bot Framework
CLI Adapter
Run Magpie locally from the command line
Custom Adapter
Build your own adapter for Slack, Telegram, or any platform
Environment Variables
Complete reference for all configuration options