2025-12-05 17:53:13 +00:00
2024-11-07 15:50:54 +07:00
2025-10-31 21:53:31 +07:00
2024-10-26 15:23:32 +07:00

🤖 ChatGPT Discord Bot

Your AI-Powered Assistant with Code Interpreter & Advanced File Management

Build and Push Version Python License Discord

FeaturesQuick StartDocumentationSupport


🌟 Overview

ChatGPT Discord Bot brings the power of AI directly to your Discord server! Powered by OpenAI's latest models and Anthropic's Claude, 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, Claude 4, 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 Interpreter

Execute Python code directly in Discord! Similar to ChatGPT's code interpreter.

import pandas as pd
import matplotlib.pyplot as plt

df = load_file('your_file_id')
print(df.describe())
plt.plot(df['column'])
plt.savefig('plot.png')

Features:

  • Auto-install packages
  • Sandboxed execution
  • File output capture
  • 5-minute timeout protection

📁 Advanced File Management

Upload, store, and process files with intelligent lifecycle management.

Supports 200+ file types:

  • 📊 Data: CSV, Excel, JSON, Parquet
  • 🖼️ Images: PNG, JPEG, GIF, SVG, PSD
  • 📄 Documents: PDF, DOCX, Markdown
  • 🔬 Scientific: MATLAB, HDF5, NumPy
  • 🎵 Media: Audio, Video formats
  • And many more!

Smart Features:

  • Auto-expiration (configurable)
  • Per-user storage limits
  • /files command for management

🎨 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-4o
  • gpt-4o-mini

GPT-5 Series

  • gpt-5
  • gpt-5-mini
  • gpt-5-nano
  • gpt-5-chat

o1/o3 Series

  • o1-preview
  • o1-mini
  • o1
  • o3-mini

Claude (Anthropic)

  • claude-sonnet-4-20250514
  • claude-opus-4-20250514
  • claude-3.5-sonnet
  • claude-3.5-haiku

🚀 Quick Start

Prerequisites

Before you begin, ensure you have:

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

# Anthropic (Claude) - Optional
ANTHROPIC_API_KEY=your_anthropic_api_key_here

# 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

  1. Upload a file - Drag and drop any file into the chat
  2. Get file ID - Bot confirms upload with file ID
  3. 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

🆕 What's New in v2.0

🛠️ 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:

  1. All required environment variables are set
  2. Discord token is valid
  3. MongoDB is accessible
  4. 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:

  1. File size (Discord limit: 25MB for free, 500MB for Nitro)
  2. Storage limit reached (default: 20 files per user)
  3. 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

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

Stars Forks Issues Pull Requests

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

View full roadmap →


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

⬆ Back to Top

Description
ChatGPT Discord bot with searching, image generation (runware api),
Readme MIT 2.8 MiB
Stable 2.0.4 Latest
2025-10-03 13:05:07 +07:00
Languages
Python 99.5%
Dockerfile 0.5%