- Updated descriptions for functions to provide clearer guidance on usage. - Added detailed parameter descriptions for better understanding. - Introduced new function `remove_background` for background removal. - Adjusted parameter requirements and constraints across various functions. - Improved overall consistency and readability of the code.
🤖 ChatGPT Discord Bot
Your AI-Powered Assistant with Code Interpreter & Advanced File Management
🌟 Overview
ChatGPT Discord Bot brings the power of AI directly to your Discord server! Powered by OpenAI's latest models, this bot goes beyond simple chat - it's a complete AI assistant with code interpretation, file management, data analysis, and much more.
🎯 What Makes This Bot Special?
- 🧠 Latest AI Models - GPT-4o, GPT-5, o1, o3-mini, and more
- 💻 Code Interpreter - Execute Python code like ChatGPT (NEW in v2.0!)
- 📁 Smart File Management - Handle 200+ file types with automatic cleanup
- 📊 Data Analysis - Upload and analyze CSV, Excel, and scientific data
- 🎨 Image Generation - Create stunning images from text prompts
- 🔍 Web Tools - Search Google and scrape websites
- ⏰ Reminder System - Never forget important tasks
- 🐳 Docker Ready - One-command deployment
✨ Features
🆕 New in Version 2.0.0
💻 Unified Code InterpreterExecute Python code directly in Discord! Similar to ChatGPT's code interpreter. Features:
|
📁 Advanced File ManagementUpload, store, and process files with intelligent lifecycle management. Supports 200+ file types:
Smart Features:
|
🎨 Image Generation
Generate stunning visuals from text prompts using Runware AI:
/generate prompt: A futuristic cyberpunk city at night with neon lights
- High-quality outputs
- Fast generation (2-5 seconds)
- Multiple style support
📊 Data Analysis & Visualization
Upload your data files and get instant insights:
📈 Statistical Analysis
• Descriptive statistics
• Correlation matrices
• Distribution plots
• Custom visualizations
📉 Supported Formats
• CSV, TSV, Excel
• JSON, Parquet, Feather
• SPSS, Stata, SAS
• And 50+ more formats
🔍 Web Tools
- Google Search - Get up-to-date information from the web
- Web Scraping - Extract and summarize website content
- PDF Analysis - Process and analyze PDF documents
🤖 AI Conversation
- Natural language understanding
- Context-aware responses
- Time-zone aware (knows current date/time)
- Multi-turn conversations
- DM and server support
⏰ Reminder System
Set reminders naturally:
"Remind me to check email in 30 minutes"
"Set a reminder for tomorrow at 3pm"
"Remind me about the meeting in 2 hours"
🎯 Supported AI Models
|
GPT-4 Series
|
GPT-5 Series
|
o1/o3 Series
|
🚀 Quick Start
Prerequisites
Before you begin, ensure you have:
- 🐳 Docker (recommended) or Python 3.13+
- 🎮 Discord Bot Token (Create one here)
- 🔑 OpenAI API Key (Get it here)
- 🎨 Runware API Key (Sign up here)
- 🔍 Google API Key (Google Cloud Console)
- 🗄️ MongoDB (MongoDB Atlas - Free tier available)
🐳 Option A: Docker Deployment (Recommended)
Step 1: Create .env file in your project directory
# Discord Configuration
DISCORD_TOKEN=your_discord_bot_token_here
# AI Provider Keys
OPENAI_API_KEY=your_openai_api_key_here
OPENAI_BASE_URL=https://api.openai.com/v1
# Image Generation
RUNWARE_API_KEY=your_runware_api_key_here
# Google Search
GOOGLE_API_KEY=your_google_api_key_here
GOOGLE_CX=your_custom_search_engine_id_here
# Database
MONGODB_URI=your_mongodb_connection_string_here
# Bot Configuration
ADMIN_ID=your_discord_user_id
TIMEZONE=Asia/Ho_Chi_Minh
# File Management (NEW in v2.0)
MAX_FILES_PER_USER=20
FILE_EXPIRATION_HOURS=48
# Code Execution (NEW in v2.0)
CODE_EXECUTION_TIMEOUT=300
Step 2: Create docker-compose.yml
version: '3.8'
services:
bot:
image: ghcr.io/coder-vippro/chatgpt-discord-bot:latest
container_name: chatgpt-discord-bot
env_file:
- .env
volumes:
- ./data/user_files:/tmp/bot_code_interpreter/user_files
- ./data/outputs:/tmp/bot_code_interpreter/outputs
restart: unless-stopped
deploy:
resources:
limits:
cpus: '2.0'
memory: 4G
Step 3: Start the bot
docker-compose up -d
Step 4: Check logs
docker-compose logs -f bot
✅ Done! Your bot is now running!
💻 Option B: Local Deployment
Step 1: Clone the repository
git clone https://github.com/Coder-Vippro/ChatGPT-Discord-Bot.git
cd ChatGPT-Discord-Bot
Step 2: Create and configure .env file
cp .env.example .env
# Edit .env with your API keys and configuration
Step 3: Install dependencies
pip install -r requirements.txt
Step 4: Run the bot
python3 bot.py
📖 Usage Guide
💬 Basic Chat
Simply mention the bot or DM it:
@Bot Hello! How can you help me?
🎨 Image Generation
Use the /generate command:
/generate prompt: A serene Japanese garden with cherry blossoms
📁 File Upload & Analysis
- Upload a file - Drag and drop any file into the chat
- Get file ID - Bot confirms upload with file ID
- Analyze - Ask the bot to analyze your data
User: *uploads data.csv*
Bot: 📊 File Uploaded: data.csv
🆔 File ID: 123456789_1234567890_abc123
User: Analyze this data and create visualizations
Bot: *executes code and generates plots*
💻 Code Execution
Ask the bot to write and execute code:
User: Calculate the fibonacci sequence up to 100 and plot it
Bot: I'll calculate and plot the Fibonacci sequence for you.
```python
def fibonacci(n):
sequence = [0, 1]
while sequence[-1] < n:
sequence.append(sequence[-1] + sequence[-2])
return sequence
import matplotlib.pyplot as plt
fib = fibonacci(100)
plt.plot(fib)
plt.title('Fibonacci Sequence')
plt.savefig('fibonacci.png')
print(f"Generated {len(fib)} numbers")
✅ Output: Generated 12 numbers 📊 Generated file: fibonacci.png
### 📋 File Management
Use the `/files` command to manage your uploaded files:
/files
This shows:
- List of all your files
- File sizes and types
- Expiration dates
- Delete option
### 🔍 Web Search
/search prompt: Latest AI developments 2025
### 🌐 Web Scraping
/web url: https://example.com/article
### 📊 User Statistics
/user_stat
Shows your token usage and model preferences.
### 🔄 Reset Conversation
/reset
Clears conversation history and deletes all uploaded files.
---
## ⚙️ Configuration
### Environment Variables
<details>
<summary><b>Click to expand full configuration options</b></summary>
#### Required Variables
| Variable | Description | Example |
|----------|-------------|---------|
| `DISCORD_TOKEN` | Your Discord bot token | `MTIzNDU2Nzg5MDEyMzQ1Njc4OQ...` |
| `OPENAI_API_KEY` | OpenAI API key | `sk-proj-...` |
| `RUNWARE_API_KEY` | Runware API key for images | `rw_...` |
| `GOOGLE_API_KEY` | Google API key | `AIza...` |
| `GOOGLE_CX` | Custom Search Engine ID | `a1b2c3d4e5f6g7h8i9` |
| `MONGODB_URI` | MongoDB connection string | `mongodb://localhost:27017/` |
#### Optional Variables
| Variable | Description | Default |
|----------|-------------|---------|
| `OPENAI_BASE_URL` | OpenAI API base URL | `https://api.openai.com/v1` |
| `ADMIN_ID` | Discord user ID for admin | None |
| `TIMEZONE` | Timezone for reminders | `UTC` |
| `MAX_FILES_PER_USER` | Max files per user | `20` |
| `FILE_EXPIRATION_HOURS` | File expiration time | `48` |
| `CODE_EXECUTION_TIMEOUT` | Code timeout in seconds | `300` |
| `ENABLE_WEBHOOK_LOGGING` | Enable webhook logs | `False` |
| `LOGGING_WEBHOOK_URL` | Webhook URL for logs | None |
</details>
### File Management Settings
```env
# Maximum files each user can upload
MAX_FILES_PER_USER=20
# Hours until files expire and are auto-deleted
# Set to -1 for permanent storage (no expiration)
FILE_EXPIRATION_HOURS=48
Code Execution Settings
# Maximum time for code execution (in seconds)
CODE_EXECUTION_TIMEOUT=300
# Package cleanup period (in code_interpreter.py)
PACKAGE_CLEANUP_DAYS=7
📚 Documentation
📖 Comprehensive Guides
- 🚀 Quick Start Guide
- 📁 File Management Guide
- 💻 Code Interpreter Guide
- 📦 Package Cleanup Guide
- 🐳 Docker Deployment Guide
- ⚙️ Environment Setup Guide
🆕 What's New in v2.0
- 📋 Release Notes v2.0.0
- 📝 Complete Implementation Summary
- 🔧 All File Types & Timeout Update
- 🐛 Bug Fixes Documentation
🛠️ Technical Documentation
🎯 Examples
Example 1: Data Analysis
User: *uploads sales_data.csv*
User: Analyze this sales data and show me:
1. Monthly revenue trends
2. Top 5 products
3. Customer distribution by region
Bot: I'll analyze your sales data and create visualizations.
[Executes Python code with pandas and matplotlib]
[Generates 3 charts]
📊 Analysis Results:
- Total Revenue: $1.2M
- Best Month: December ($250K)
- Top Product: Product A ($300K)
- Main Region: North America (45%)
📈 Generated 3 visualizations
Example 2: Image Generation
User: /generate prompt: A serene Japanese garden with cherry blossoms, koi pond, and traditional temple in the background, anime style
Bot: 🎨 Generating your image...
[2 seconds later]
🖼️ Here's your generated image!
[Beautiful anime-style Japanese garden image]
Example 3: Code Execution
User: Create a function to check if a number is prime, then find all primes up to 1000
Bot: I'll create a prime checker and find all primes up to 1000.
```python
def is_prime(n):
if n < 2:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
primes = [n for n in range(2, 1001) if is_prime(n)]
print(f"Found {len(primes)} prime numbers")
print(f"First 10: {primes[:10]}")
print(f"Last 10: {primes[-10:]}")
✅ Output: Found 168 prime numbers First 10: [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] Last 10: [937, 941, 947, 953, 967, 971, 977, 983, 991, 997]
---
## 🤝 Contributing
We welcome contributions! Here's how you can help:
### Ways to Contribute
- 🐛 **Report Bugs** - [Open an issue](https://github.com/Coder-Vippro/ChatGPT-Discord-Bot/issues)
- ✨ **Suggest Features** - [Start a discussion](https://github.com/Coder-Vippro/ChatGPT-Discord-Bot/discussions)
- 📝 **Improve Docs** - Submit documentation updates
- 💻 **Submit Code** - Create pull requests
### Development Setup
```bash
# Fork and clone the repository
git clone https://github.com/YOUR_USERNAME/ChatGPT-Discord-Bot.git
cd ChatGPT-Discord-Bot
# Install dependencies
pip install -r requirements.txt
# Create a branch
git checkout -b feature/your-feature-name
# Make your changes and test
python3 bot.py
# Run tests
pytest tests/
# Commit and push
git add .
git commit -m "Add your feature"
git push origin feature/your-feature-name
Code of Conduct
Please read our Code of Conduct before contributing.
🐛 Troubleshooting
Bot won't start
Check:
- All required environment variables are set
- Discord token is valid
- MongoDB is accessible
- Port 27017 is not blocked (if using local MongoDB)
Solution:
# Check logs
docker-compose logs bot
# Verify .env file
cat .env | grep -v '^#'
Code execution fails
Common causes:
- Package installation timeout
- Code exceeds 5-minute timeout
- Memory limit exceeded
Solutions:
# Increase timeout
CODE_EXECUTION_TIMEOUT=600
# In docker-compose.yml, increase memory
memory: 8G
Files not uploading
Check:
- File size (Discord limit: 25MB for free, 500MB for Nitro)
- Storage limit reached (default: 20 files per user)
- Disk space available
Solution:
# Increase file limit
MAX_FILES_PER_USER=50
# Set permanent storage
FILE_EXPIRATION_HOURS=-1
Docker "Resource busy" error
This is fixed in v2.0! The bot now uses system Python in Docker.
If you still see this error:
# Rebuild from scratch
docker-compose down
docker-compose build --no-cache
docker-compose up -d
📊 Performance
System Requirements
| Deployment | CPU | RAM | Disk | Network |
|---|---|---|---|---|
| Minimal | 1 core | 2GB | 2GB | 1 Mbps |
| Recommended | 2 cores | 4GB | 5GB | 10 Mbps |
| High Load | 4 cores | 8GB | 10GB | 100 Mbps |
Benchmarks
📈 Response Times (avg):
- Simple chat: 1-2 seconds
- Code execution: 2-5 seconds
- Image generation: 3-5 seconds
- Data analysis: 5-10 seconds
- File upload: <1 second
💾 Resource Usage:
- Idle: ~200 MB RAM
- Active: ~500 MB RAM
- Peak: ~2 GB RAM
- Docker image: ~600 MB
🚀 Throughput:
- Concurrent users: 50+
- Messages/minute: 100+
- File uploads/hour: 500+
🔒 Security
Security Features
- ✅ Sandboxed code execution
- ✅ Per-user file isolation
- ✅ Timeout protection
- ✅ Resource limits
- ✅ Input validation
- ✅ Package validation
- ✅ MongoDB injection prevention
Reporting Security Issues
Found a vulnerability? Please DO NOT open a public issue.
See SECURITY.md for reporting guidelines.
📜 License
This project is licensed under the MIT License - see the LICENSE file for details.
🙏 Acknowledgments
Special thanks to:
- OpenAI - For powering our AI capabilities
- Runware - For image generation API
- Discord.py - For excellent Discord library
- MongoDB - For reliable database services
- All Contributors - For making this project better
📞 Support & Community
Get Help
- 💬 Discord Server: Join our community
- 🐛 GitHub Issues: Report bugs
- 💡 Discussions: Share ideas
Useful Commands
# View logs
docker-compose logs -f bot
# Restart bot
docker-compose restart bot
# Check file storage
du -sh data/user_files/
# View package cache
cat /tmp/bot_code_interpreter/package_cache.json | jq
# Update to latest version
docker-compose pull
docker-compose up -d
📈 Stats & Updates
Latest Release: v2.0.0 (October 3, 2025)
Active Servers: Growing daily
🗺️ Roadmap
Version 2.1 (Q4 2025)
- Multi-language support
- Voice channel integration
- Usage analytics dashboard
- Advanced reminders (recurring)
- Custom tool creation
Version 2.2 (Q1 2026)
- Collaborative code sessions
- Code version history
- Direct database connections
- Mobile companion app
- Workflow automation
⭐ Star Us on GitHub!
If you find this bot useful, please give it a star! It helps others discover the project.
Made with ❤️ by Coder-Vippro