Discord Integration
Table of contents
- Discord Integration
Discord integration allows you to interact with AI assistants via Discord messages.
Features
- Bidirectional Communication: Send messages from Discord to chat.nvim and receive responses
- Session Binding: Bind specific Discord channels to chat.nvim sessions
- Remote Control: Use Discord commands to manage sessions remotely
- Automatic Polling: Bot polls for new messages every 3 seconds
- Message Mentions: Bot responds to mentions and replies
- Auto-chunking: Messages > 2,000 characters are automatically split
Setup Guide
1. Create Discord Application
- Go to https://discord.com/developers/applications
- Click “New Application”
- Give it a name (e.g., “Chat.nvim Bot”)
2. Create Bot User
- Navigate to “Bot” section
- Click “Add Bot”
- Copy the Token (this is your
integrations.discord.token)
Keep your bot token secure! Never share it or commit it to version control.
3. Enable Message Content Intent
- Under “Privileged Gateway Intents”
- Enable “Message Content Intent” ✅
- Save changes
Message Content Intent is required for the bot to read message content in servers.
4. Get Channel ID
- Enable Developer Mode in Discord (User Settings → Advanced → Developer Mode)
- Right-click your channel → Copy ID (this is your
integrations.discord.channel_id)
5. Invite Bot to Server
- Go to “OAuth2” → “URL Generator”
- Select “bot” scope
- Required permissions: “Read Messages”, “Send Messages”, “Read Message History”
- Copy and open the generated URL
- Authorize the bot
6. Configure chat.nvim
require('chat').setup({
integrations = {
discord = {
token = 'YOUR_DISCORD_BOT_TOKEN',
channel_id = 'YOUR_CHANNEL_ID',
},
},
})
Commands
Neovim Commands
| Command | Description |
|---|---|
:Chat bridge discord |
Bind current session to Discord channel |
Discord Commands
| Command | Description |
|---|---|
/session |
Bind current Discord channel to active chat.nvim session |
/clear |
Clear messages in the bound session |
Workflow
- Configure Discord bot token and channel ID
- Open chat.nvim and create/start a session
- Run
:Chat bridge discordto bind the session - In Discord, type
/sessionto confirm binding - Mention the bot or reply to its messages to interact
- AI response will be sent back to Discord automatically
The bot only responds when mentioned or when replying to its messages in group channels.
Message Handling
Mentions
In group channels, mention the bot to get a response:
@Chat.nvim Bot What is the weather today?
Replies
Reply to any bot message to continue the conversation:
[Reply to bot's message]
Can you provide more details?
Direct Messages
In direct messages, just send a message:
Hello, how can you help me?
Technical Details
- API: Discord REST API v10
- Polling: 3-second intervals
- Message Limit: Auto-chunking for messages > 2,000 characters
- State Persistence:
stdpath('data')/chat-discord-state.json - Timeout Protection: 5-second request timeout
Troubleshooting
Bot Not Responding
Symptom: Bot does not respond to messages.
Solution:
- Verify token and channel_id are correct
- Check bot has “Message Content Intent” enabled
- Ensure bot is invited with proper permissions
- Make sure you’re mentioning the bot or replying to its messages
Permission Errors
Symptom: Bot lacks permissions to read/send messages.
Solution:
- Re-invite the bot with correct permissions
- Check server role permissions
- Verify channel permissions for the bot
State Issues
Symptom: Session binding not working.
Solution:
- Clear state:
:lua require('chat.integrations.discord').clear_state()
Best Practices
1. Use Dedicated Channel
Create a dedicated channel for the bot to avoid noise:
#ai-assistant
2. Limit Bot Access
Only invite the bot to channels where you need AI assistance.
3. Monitor Token Usage
Keep track of your AI provider’s token usage when using Discord integration.
4. Regular Cleanup
Periodically clear old sessions to maintain performance:
:Chat clear
Next Steps
- Telegram Integration - Setup Telegram bot
- Slack Integration - Setup Slack bot
- IM Integration Overview - All IM integrations