Discord has become a natural interface for AI agents. Teams use it for notifications, status updates, and interactive communication with their AI systems. But connecting AI agents to Discord in a production environment requires more than a weekend hack. It requires enterprise-grade security, reliable message handling, and proper audit trails.
systemprompt.io provides this out of the box. Its Discord integration enables bidirectional communication between your AI agents and Discord servers, with all the security and reliability features you need for production deployments.
This guide explains how the integration works and how to configure it for your environment.
How systemprompt.io Works
Before diving into Discord specifics, it's important to understand the systemprompt.io model. This is not a framework where you write code. It is production infrastructure for AI agents.
The workflow is simple:
- Playbooks contain instructions - Detailed documentation for how to accomplish tasks
- AI agents read playbooks - Claude Code, Codex, or other AI coding assistants follow these instructions
- Agents implement fully - The AI handles all configuration, testing, and deployment
- You guide and verify - You provide direction and validate the results
This means you don't write Python scripts or manually edit configuration files. You work with an AI assistant, point it at the relevant playbook, and it handles the implementation.
For Discord integration, the playbook is guide_discord:
systemprompt core playbooks show guide_discord
What the Discord Integration Provides
systemprompt.io's Discord integration supports two communication modes:
| Mode | Direction | Purpose |
|---|---|---|
| CLI (Outbound) | Agent → Discord | Send notifications, alerts, status updates |
| Gateway (Inbound) | Discord → Agent | Receive messages, trigger agent workflows |
This enables powerful workflows:
- Agents can report their status to a Discord channel
- Users can send commands to agents via Discord
- Scheduled heartbeat messages confirm system health
- All interactions are logged for audit purposes
Prerequisites
Before configuring Discord integration, ensure you have:
- A running systemprompt.io instance connected to PostgreSQL
- A Discord account with permissions to create applications
- An AI coding assistant (Claude Code, Codex, etc.) to help with configuration
Setting Up Your Discord Application
The Discord Developer Portal setup is straightforward. This is the one part you'll do manually in a web browser.
1. Create the Application
Navigate to the Discord Developer Portal and create a new application:
- Click New Application
- Name it (e.g., "systemprompt Agent")
- Accept the terms
2. Create and Configure the Bot
In the application settings:
- Navigate to Bot in the sidebar
- Click Add Bot and confirm
- Under Privileged Gateway Intents, enable MESSAGE CONTENT INTENT
- Click Reset Token and copy the token securely
The MESSAGE CONTENT INTENT is critical. Without it, the gateway cannot read message content.
3. Invite the Bot to Your Server
- Navigate to OAuth2 > URL Generator
- Select the
botscope - Select permissions:
- Read Messages/View Channels
- Send Messages
- Read Message History
- Copy the generated URL and open it in your browser
- Select your server and authorise
Your bot will appear offline until the gateway is configured and running.
Configuring systemprompt.io
With your Discord application created, configuration happens through the CLI and configuration files. Your AI assistant handles this by following the guide_discord playbook.
Token Management
The bot token is stored securely in your profile's secrets:
# Your AI assistant will configure this
# Location: ~/.systemprompt/profiles/<profile>/secrets.json
systemprompt.io uses a SecretString type internally. This automatically redacts the token from all logs, debug output, and error traces. Your token never appears in plain text anywhere in the system.
Configuration File
The Discord configuration lives in services/config/discord.yaml. The structure is:
# Default targets for outbound messages
default_channel_id: "1234567890123456789"
default_user_id: "9876543210987654321"
# Master switch
enabled: true
# Gateway configuration for inbound messages
gateway:
enabled: true
target_agent: "systemprompt_hub"
message_prefix: "DISCORD_MESSAGE"
ignore_channels: []
ignore_bots: true
Key settings:
| Setting | Purpose |
|---|---|
target_agent |
The agent that receives incoming Discord messages |
message_prefix |
Identifies messages from Discord in agent input |
ignore_bots |
Prevents bot-to-bot loops (critical for production) |
ignore_channels |
Excludes specific channels from monitoring |
Security Architecture
systemprompt.io's Discord integration includes enterprise-grade security features that you get automatically.
Token and Secret Isolation
The bot token is never written to configuration files. It's loaded from the secrets store at runtime. This enables:
- Version-controlled configuration (without secrets)
- Integration with managed secret stores (AWS Secrets Manager, HashiCorp Vault)
- Clean separation between configuration and credentials
Snowflake ID Validation
Discord IDs are validated against the Snowflake format (17-20 digit numerical strings). Malformed IDs are rejected immediately with clear error messages, preventing issues from propagating through the system.
Bot Loop Prevention
The ignore_bots: true setting prevents a common production disaster: infinite loops where bots respond to each other. Without this protection, a single misconfigured bot can consume your API quota in minutes and potentially get your application banned.
Message Deduplication
The Discord Gateway occasionally delivers duplicate messages during reconnects. systemprompt.io maintains a cache of the last 1000 message IDs and silently discards duplicates. Your agent processes each message exactly once.
Rate Limit Handling
Discord enforces strict rate limits. The systemprompt.io client automatically:
- Reads
Retry-Afterheaders from 429 responses - Backs off for the specified duration
- Falls back to a 60-second cooldown if the header is missing
This prevents your bot from being temporarily or permanently banned for rate limit violations.
Immutable Audit Trail
Every Discord interaction is logged to the PostgreSQL database:
- Inbound messages received by the gateway
- Outbound messages sent by agents
- Timestamps for all events
- Full message metadata
Security teams can query this log to trace any action back to its source.
How Agents Communicate
Receiving Messages
When a user posts in a monitored channel, the gateway formats the message and forwards it to the configured target agent:
DISCORD_MESSAGE: channel=1234567890 (general) author=username content=Hello agent!
The agent's instructions should include guidance on parsing and responding to this format.
Sending Messages
Agents send messages using the CLI:
# Send to default channel
systemprompt plugins run discord send "Status update: all systems operational"
# Send to specific channel
systemprompt plugins run discord send "Alert: high memory usage" --channel 876543210987654321
These commands are available to agents through the systemprompt MCP tool.
Automation with Jobs
systemprompt.io's job scheduler manages the Discord gateway and enables automated messaging.
Gateway Job
The soul_discord_gateway job maintains the persistent WebSocket connection:
- Schedule:
@reboot(starts automatically) - Runs continuously, reconnecting as needed
- Forwards incoming messages to the target agent
Heartbeat Job
The soul_heartbeat job demonstrates proactive messaging:
- Runs on a configurable schedule (e.g., hourly)
- Triggers the agent to perform a status check
- Reports results to a designated Discord channel
This confirms the entire system is healthy: scheduler, agent, and Discord API connectivity.
Managing Jobs
# View all jobs
systemprompt infra jobs list
# Check gateway status
systemprompt infra jobs list | grep discord
# View recent logs
systemprompt infra logs view --limit 50
Testing the Integration
After configuration, verify the integration:
# Test API connectivity
systemprompt plugins run discord test
# Send a test message
systemprompt plugins run discord send "Integration test successful"
# Verify gateway is running
systemprompt infra jobs list
A successful test confirms:
- The bot token is valid
- The bot has necessary permissions
- API connectivity is working
Troubleshooting
Bot Appears Offline
- Check that
soul_discord_gatewayis running:systemprompt infra jobs list - Test the token:
systemprompt plugins run discord test - Review logs for connection errors:
systemprompt infra logs view --level error
Messages Not Received
- Verify MESSAGE CONTENT INTENT is enabled in the Developer Portal
- Check the channel isn't in
ignore_channels - Confirm you're not testing with another bot while
ignore_bots: true - Verify the bot has Read Messages permission in the channel
Agent Returns Errors
- Check the target agent exists:
systemprompt admin agents list - Verify the agent's AI provider is configured correctly
- Review agent-specific logs:
systemprompt infra logs trace list --agent <name>
Summary
systemprompt.io's Discord integration provides production-grade connectivity between your AI agents and Discord. The security features—token isolation, rate limiting, loop prevention, and audit logging—are built in, not bolted on.
To configure it for your environment:
- Create a Discord application and bot
- Enable MESSAGE CONTENT INTENT
- Invite the bot to your server
- Work with your AI assistant to follow the
guide_discordplaybook
The playbook contains the complete, up-to-date instructions:
systemprompt core playbooks show guide_discord
Your AI assistant reads the playbook and handles the implementation. You provide direction and verify the results. That's the systemprompt.io model: production infrastructure that gets out of your way.