A powerful Discord AI bot built with advanced language models, MCP (Model Context Protocol) servers, and comprehensive tooling support. Created by indrazm.
- GPT-4.1 Integration: Leverages OpenAI's latest model for intelligent responses
- Conversation Memory: Maintains context across Discord threads and channels
- Multi-modal Support: Handles both text and image inputs
- Casual & Friendly Tone: Designed for natural, conversational interactions
- Web Search: Real-time web search capabilities for up-to-date information
- GitHub Integration: Fetch and analyze GitHub repository content using gitingest
- Context7 MCP Server: Access to latest documentation for programming languages and frameworks
- Multi-language Support: Responds in Bahasa Indonesia when detected, keeping technical terms in English
- Smart Channel Monitoring: Auto-replies in monitored channels
- Thread Management: Creates organized conversation threads
- Mention Handling: Responds when mentioned with
@bot
- Image Processing: Analyzes and responds to image attachments
- Long Message Support: Handles responses that exceed Discord's character limits
- Langfuse Integration: Comprehensive conversation tracking and analytics
- Logfire Support: Advanced logging and monitoring
- Database Persistence: SQLite database for conversation history
- Error Handling: Robust error handling and logging
- Python 3.12+
- Discord Bot Token
- OpenAI API Key
- Node.js (for MCP servers)
-
Clone the repository
git clone <repository-url> cd discord-ai
-
Install dependencies
uv sync
-
Environment Setup
cp .env.example .env
Fill in your environment variables:
DISCORD_TOKEN=your_discord_bot_token MONITORED_CHANNEL_ID=your_channel_id OPENAI_API_KEY=your_openai_api_key LANGFUSE_SECRET_KEY=your_langfuse_secret LANGFUSE_PUBLIC_KEY=your_langfuse_public LANGFUSE_HOST=your_langfuse_host
-
Database Setup
uv run alembic upgrade head
-
Run the Bot
make serve
app/
βββ core/
β βββ settings.py # Configuration management
βββ database/
β βββ connection.py # Database connection
β βββ models.py # SQLModel definitions
β βββ service.py # Database operations
βββ discord/
β βββ bot.py # Discord bot setup
β βββ commands.py # Bot commands
β βββ events.py # Event handlers setup
β βββ handler.py # Main event handling logic
β βββ utils.py # Discord utilities
βββ llm/
β βββ agent.py # AI agent configuration
β βββ mcps.py # MCP server management
β βββ prompts.py # System prompts
β βββ tools/
β β βββ github.py # GitHub integration tool
β βββ utils.py # LLM utilities
βββ main.py # Application entry point
- Powered by OpenAI's GPT-4.1
- Integrates with MCP servers for enhanced capabilities
- Supports multi-modal inputs (text + images)
- Maintains conversation context
- SQLite database with SQLModel ORM
- Conversation history persistence
- Alembic migrations support
- Efficient conversation retrieval
- Context7 server for documentation access
- Extensible MCP server management
- Async context management for server lifecycle
!ping
- Check bot latency!check_channel
- Verify channel monitoring status
- Monitored Channel: Bot auto-replies to all messages
- Mention Mode: Use
@BotName
to start conversations - Thread Conversations: Maintains context within threads
User: @DevscaleAI How do I use React hooks?
Bot: lemme check the latest React docs for you! π
[Bot provides comprehensive React hooks explanation with examples]
User: Can you analyze this GitHub repo? https://github.com/user/project
Bot: Sure! Let me fetch and analyze that repo for you π
[Bot provides detailed repository analysis]
Variable | Description | Required |
---|---|---|
DISCORD_TOKEN |
Discord bot token | β |
MONITORED_CHANNEL_ID |
Channel ID for auto-replies | β |
OPENAI_API_KEY |
OpenAI API key | β |
LANGFUSE_SECRET_KEY |
Langfuse secret key | β |
LANGFUSE_PUBLIC_KEY |
Langfuse public key | β |
LANGFUSE_HOST |
Langfuse host URL | β |
DATABASE_PATH |
SQLite database path | β |
DATABASE_ECHO |
Enable SQL query logging | β |
Ensure your Discord bot has these permissions:
- Read Messages
- Send Messages
- Create Public Threads
- Send Messages in Threads
- Embed Links
- Attach Files
- Read Message History
- Use Slash Commands
- Ruff: Linting and formatting
- Type Hints: Full type annotation support
- Async/Await: Modern async Python patterns
- Error Handling: Comprehensive error management
- Create a new tool in
app/llm/tools/
- Use the
@function_tool
decorator - Add the tool to the agent in
app/llm/agent.py
from agents import function_tool
@function_tool
async def my_custom_tool(param: str) -> str:
"""Tool description for the AI agent"""
# Tool implementation
return result
- Add server configuration in
app/llm/mcps.py
- Include in the
get_all_mcp_servers()
function
def get_my_mcp_server():
return MCPServerStdio(
params={
"command": "npx",
"args": ["-y", "my-mcp-server@latest"],
}
)
This project is licensed under the MIT License - see the LICENSE file for details.
Created by indrazm.
Contributions are welcome! Please feel free to submit issues and pull requests.
For support and questions, please create an issue in the repository or contact indrazm.
Built with β€οΈ using Python, Discord.py, OpenAI, and MCP servers