Discord
Set up CodeSpar as a Discord bot with message content intent for @mention-driven agent interactions in your server.
Discord Channel
CodeSpar integrates with Discord as a bot application. Once added to your server, team members can @mention the bot in any channel to interact with agents — reviewing PRs, deploying code, investigating incidents, and more.
Prerequisites
- A Discord server where you have Manage Server permission
- CodeSpar instance running (Docker or local)
Create a Discord Bot
Step 1: Create an Application
- Go to the Discord Developer Portal
- Click New Application
- Name it
CodeSparand click Create
Step 2: Create a Bot User
- In the left sidebar, click Bot
- Click Add Bot and confirm
- Under the bot's username, click Reset Token
- Copy the token — this is your
DISCORD_BOT_TOKEN
Important: Keep this token secret. Anyone with it can control the bot.
Step 3: Enable Privileged Intents
Under the Bot settings page, enable these Privileged Gateway Intents:
| Intent | Purpose |
|---|---|
| Message Content Intent | Required to read the text content of messages |
| Server Members Intent | Optional — needed if you want to resolve usernames |
Without Message Content Intent, the bot can see that a message was sent but cannot read its text, making it unable to parse commands.
Step 4: Configure Permissions
Under OAuth2 → URL Generator:
- Select the
botscope - Select these bot permissions:
- Send Messages — respond to commands
- Read Message History — context for conversations
- Add Reactions — acknowledge commands with emoji
- Use Slash Commands — optional, for future slash command support
- Attach Files — send diffs, reports, and logs
- Embed Links — format responses with rich embeds
The minimum required permission integer is 277025770560.
Step 5: Invite the Bot to Your Server
- In OAuth2 → URL Generator, copy the generated URL
- Open it in your browser
- Select the server to add the bot to
- Click Authorize
Environment Variables
Add these to your .env file:
| Variable | Required | Description |
|---|---|---|
ENABLE_DISCORD | Yes | Set to true to activate the Discord channel |
DISCORD_BOT_TOKEN | Yes | The bot token from Discord Developer Portal |
How It Works
The Discord adapter uses discord.js to connect to the Discord Gateway via WebSocket.
Connection Flow
- On startup, the adapter logs into Discord using the bot token
- A WebSocket connection is established to the Discord Gateway
- The bot appears as "Online" in your server's member list
- The adapter listens for
messageCreateevents
Mention Detection
Discord has native @mention support. When a user types @CodeSpar, Discord replaces it with a mention reference containing the bot's user ID:
Threading
Discord supports threads natively. When CodeSpar responds to a message, it can reply in the same thread or create a new one for long-running operations:
Channel Linking
After adding the bot to your server, link a Discord channel to a CodeSpar project:
This associates the channel with the repository. All subsequent commands in that channel will operate on that project.
Multiple channels can be linked to different projects within the same server:
Capabilities
| Feature | Support |
|---|---|
| Threads | Yes — replies in threads, can create threads |
| Reactions | Yes — emoji reactions for acknowledgment |
| Rich formatting | Yes — Markdown, code blocks, embeds |
| File uploads | Yes — diffs, logs, reports as attachments |
| Message editing | Yes — can edit its own previous messages |
| Embeds | Yes — rich embedded content with fields |
Troubleshooting
Bot appears offline
- Verify
ENABLE_DISCORD=truein your environment - Check that
DISCORD_BOT_TOKENis correct and not expired - Look for connection errors in CodeSpar logs
- Ensure the bot has not been removed from the server
Bot is online but doesn't respond
- Confirm Message Content Intent is enabled in the Developer Portal
- Verify the bot has Send Messages permission in the channel
- Check that the bot can see the channel (channel permissions may restrict visibility)
- Ensure the message contains a proper @mention (not just typing "codespar")
"Missing Access" or "Missing Permissions" errors
The bot lacks required permissions in the channel or server. Either:
- Update the bot's role permissions in Server Settings → Roles
- Re-invite the bot with the correct permission set using the OAuth2 URL
Rate limiting
Discord enforces rate limits on API calls. CodeSpar handles this automatically with exponential backoff, but if you see delayed responses, check for excessive message volume in your channels.
Add to Discord (OAuth Install)
For a streamlined installation experience, CodeSpar provides an OAuth-based install flow. Instead of manually constructing an OAuth2 URL in the Developer Portal, you can use the built-in install endpoint.
Install Endpoint
This endpoint redirects the user to Discord's authorization URL with the correct scopes and permissions pre-configured. After the user authorizes the bot, Discord redirects back to your CodeSpar instance.
The redirect URL is constructed using the DISCORD_CLIENT_ID environment variable:
Environment Variable
Add DISCORD_CLIENT_ID to your .env file to enable the OAuth install flow:
| Variable | Required | Description |
|---|---|---|
DISCORD_CLIENT_ID | For OAuth install | Application ID from the Discord Developer Portal (General Information tab) |
This is separate from DISCORD_BOT_TOKEN. The client ID is public and safe to expose in URLs; the bot token must remain secret.
Multi-Tenant Support
Discord bots are inherently multi-tenant. A single bot token works across all servers (guilds) the bot has been added to. There is no per-server token or configuration required.
When the bot receives a message, the Discord Gateway includes the guild ID and channel ID in the event payload. CodeSpar uses these identifiers to route messages to the correct project agent based on channel linking.
This means:
- One CodeSpar instance can serve multiple Discord servers simultaneously
- Each server can have different channels linked to different projects
- No additional configuration is needed per server beyond the initial bot invite
Image Vision
Discord supports image attachments natively. When a user attaches an image to a message that mentions the bot, CodeSpar extracts the image automatically and sends it to Claude for visual analysis.
How It Works
- The user sends a message with an image attachment:
@CodeSpar fix this UI bug [attached: screenshot.png] - The Discord adapter reads
message.attachmentsfrom the event payload - Each attachment has a public URL (
attachment.url) that can be downloaded without authentication - The image is downloaded, base64-encoded, and included as an image content block in the Claude request
Unlike Slack (which requires files:read scope and bot token authentication), Discord attachment URLs are publicly accessible. No additional scopes or permissions are needed beyond the standard bot setup.
Supported Formats
PNG, JPEG, GIF, and WEBP images up to 4 MB. Larger images are skipped with a warning. See Image Vision for full details.