Features
- Command support:
!help,!new,!status,!model,!clear,!compact,!version - Message content access: Full message content with required intents
- File attachments: Send files directly in Discord channels
- Message splitting: Handles messages up to 2,000 characters
- User allowlists: Restrict bot access to specific user IDs
- Server and DM support: Works in both server channels and direct messages
Prerequisites
Install the Discord channel dependencies:discord.py (async native) for bot functionality.
Creating a Discord Bot
- Message Content Intent (required to read message content)
- Read Messages/View Channels
- Send Messages
- Attach Files
- Read Message History
Never share your bot token! Anyone with the token can control your bot. If you accidentally expose it, click “Regenerate” to get a new one.
Configuration
Add the Discord configuration to yourconfig.yaml:
Environment Variables
For better security, use environment variables:User Allowlist
Restrict bot access to specific users:To find your Discord user ID:
- Enable Developer Mode in Discord (User Settings → Advanced → Developer Mode)
- Right-click your username and select “Copy ID”
allow_from is empty or omitted, anyone in servers with the bot can use it.
Bot Commands
The Discord bot supports these commands (defined inchannels/discord.py:22-30). Commands can use either ! or / prefix:
!help or /help
Lists all available commands with descriptions.
!new or /new
Starts a fresh conversation by clearing the session:
!status or /status
Shows current session information:
!model [name] or /model [name]
Shows the current model or switches to a different one:
!clear or /clear
Clears the entire conversation history:
!compact or /compact
Summarizes and compresses the session history:
!version or /version
Shows the Grip AI version:
Message Handling
The Discord channel processes all messages that meet these criteria (reference:channels/discord.py:72-115):
- Not from the bot itself: Ignores messages sent by the bot
- Not from other bots: Ignores messages from other bots
- User is allowed: Passes allowlist check (if configured)
Text Messages
All non-command text messages are forwarded to the agent for processing.Commands
Messages starting with! or / are checked against the command list. If the command is recognized, it’s processed as a command. Unknown commands are ignored and treated as regular messages.
Message Metadata
Each message includes metadata:Sending Files from Agent
The agent can send files to Discord channels. All files are sent as Discord attachments with optional captions. Implementation reference:channels/discord.py:153-182
Example agent response with file:
text field is sent as the message content, and the file is attached.
Message Length Limits
Discord enforces a 2,000 character limit per message. Long responses are automatically split on newline boundaries when possible. Implementation:channels/base.py:78-101
Example:
Channel and Guild IDs
The Discord channel uses channel IDs (not names) for message routing:- Server channels: Use the channel ID where the message was sent
- Direct messages: Use the DM channel ID
guild_id is included in metadata for server messages (empty for DMs).
To find a channel ID:
- Enable Developer Mode in Discord (User Settings → Advanced → Developer Mode)
- Right-click a channel and select “Copy ID”
Connection Process
The Discord channel uses an async connection process (reference:channels/discord.py:46-125):
Error Handling
The channel implements graceful error handling: Connection timeout: Raises error if bot doesn’t connect within 30 seconds Channel not found: Attempts to fetch channel if not in cache File not found: Sends error message instead of file Send failures: Logs error and continues operationImplementation Reference
The Discord channel is implemented inchannels/discord.py:
- Bot initialization:
discord.py:46-63 - Connection process:
discord.py:117-125 - Message handler:
discord.py:72-115 - Send methods:
discord.py:136-182 - Command list:
discord.py:22-30
Troubleshooting
Bot doesn’t respond
- Check that the token is correct in your configuration
- Verify the bot is enabled:
channels.discord.enabled: true - Ensure “Message Content Intent” is enabled in the Developer Portal
- Check logs for connection errors
- Verify you’re not blocked by the
allow_fromlist
”discord.py not found” error
Install the Discord channel dependencies:Bot connects but can’t read messages
Enable “Message Content Intent” in the Discord Developer Portal:- Go to your application in the Developer Portal
- Navigate to “Bot”
- Under “Privileged Gateway Intents”, enable “Message Content Intent”
- Restart your Grip AI instance
Connection timeout error
This usually indicates:- Invalid bot token
- Network connectivity issues
- Discord API outage
Bot responds to everyone (security concern)
Add a user allowlist:Next Steps
Message Bus
Learn how channels integrate with the message bus
Slack Setup
Set up a Slack bot using Socket Mode