Prerequisites
Before deploying the Discord bot, ensure you have:- Rust 1.75+ installed via rustup
- Claude CLI configured (required for both Tier 1 and Tier 2 LLM operations)
- GitHub CLI (
gh) authenticated for creating PRs - A Discord application with a bot token
- Git for cloning repositories
Creating a Discord Bot Application
Create Discord Application
- Go to the Discord Developer Portal
- Click New Application and give it a name (e.g., “Magpie”)
- Navigate to the Bot section in the left sidebar
- Click Add Bot to convert your application to a bot
Configure Bot Permissions
Under the Bot section:
- Enable MESSAGE CONTENT INTENT (required to read message text)
- Enable SERVER MEMBERS INTENT (optional, for user context)
- Select scopes:
bot - Select bot permissions:
Read Messages/View ChannelsSend MessagesSend Messages in ThreadsCreate Public ThreadsManage Threads
Get Bot Token
- In the Bot section, click Reset Token
- Copy the token (you’ll need this for
DISCORD_TOKEN) - Keep this token secret — treat it like a password
Environment Configuration
The Discord bot requires several environment variables. Create a.env file or set them in your deployment environment:
Required Variables
Pipeline Configuration
Optional: Plane Issue Tracking
Optional: Daytona Sandbox
Building and Running
Build the Discord Bot
Build the The compiled binary will be at
magpie-discord binary from the workspace root:target/release/magpie-discord.First build takes 4-5 minutes due to transitive dependencies (Goose, candle, tree-sitter, etc.).
Run the Bot Locally
Set your environment variables and run:Or run the compiled binary directly:You should see:
Test the Bot
In your Discord server:
- Mention the bot in any channel:
@Magpie add a health check endpoint - The bot will create a thread and reply with “Working on it…”
- After the pipeline completes, you’ll receive a status message with:
- Pipeline status (Success/PartialSuccess/Failed)
- PR URL (if created)
- Plane issue ID (if configured)
- CI status
- The thread will be automatically archived and locked
Production Deployment
Running as a Systemd Service
Create a systemd service file at/etc/systemd/system/magpie-discord.service:
Docker Deployment
See the Docker Setup Guide for containerized deployment options.Process Management with PM2
Alternatively, use PM2 for process management:Architecture
The Discord bot implements theChatPlatform trait from magpie-core:
- Event Handler: Listens for messages mentioning the bot using Serenity (Discord library)
- Thread Creation: Creates a new thread for each task to keep context isolated
- Pipeline Trigger: Calls
run_pipeline()with the Discord platform adapter - Thread Archival: Archives and locks threads after pipeline completion
Key Files
| File | Purpose |
|---|---|
crates/magpie-discord/src/main.rs:26 | Reads DISCORD_TOKEN and builds PipelineConfig |
crates/magpie-discord/src/handler.rs | Serenity event handler for message events |
crates/magpie-discord/src/adapter.rs | ChatPlatform implementation for Discord |
crates/magpie-discord/src/reply.rs | Formats pipeline results for Discord |
Gateway Intents
The bot requires these Discord Gateway intents (configured in code atmain.rs:30):
Troubleshooting
Bot doesn’t respond to mentions
Check MESSAGE_CONTENT intent
Check MESSAGE_CONTENT intent
Ensure MESSAGE CONTENT INTENT is enabled in Discord Developer Portal under Bot settings.
Verify bot permissions
Verify bot permissions
The bot needs:
- Read Messages/View Channels
- Send Messages
- Send Messages in Threads
- Create Public Threads
- Manage Threads
Check logs
Check logs
Run with verbose logging:
Pipeline fails immediately
Verify Claude CLI is configured
Verify Claude CLI is configured
Test the Claude CLI:
Check GitHub CLI authentication
Check GitHub CLI authentication
Verify repository access
Verify repository access
Ensure
MAGPIE_REPO_DIR points to a valid git repository with remote configured.Thread not archived after completion
This is expected ifclose_thread() fails. Check that the bot has Manage Threads permission in the channel.
Next Steps
Docker Setup
Containerize the Discord bot for easier deployment
Pipeline Configuration
Learn about all available pipeline settings
Blueprint Engine
Understand how Magpie orchestrates agent tasks
Org-Scoped Repos
Enable dynamic multi-repository support