Co-authored-by: cauvang32 <113093128+cauvang32@users.noreply.github.com>
ChatGPT Discord Bot
Overview
Welcome to ChatGPT Discord Bot! This bot provides a powerful AI assistant for Discord users, powered by OpenAI's latest models. It not only generates text responses but also offers a range of advanced features including image generation, data analysis, web searching, and reminders. The bot is designed for easy deployment with Docker and includes CI/CD integration via GitHub Actions.
Features
- Advanced AI Conversations: Uses OpenAI's latest models (including openai/gpt-4o) for natural language interactions
- Image Generation: Creates custom images from text prompts using Runware's API
- Data Analysis: Analyzes CSV and Excel files with visualizations (distributions, correlations, box plots, etc.)
- Code Interpretation: Executes Python code for calculations and data processing
- Reminder System: Sets timed reminders with custom timezone support
- Web Tools:
- Google Search: Searches the web and provides relevant information
- Web Scraping: Extracts and summarizes content from websites
- PDF Analysis: Processes and analyzes PDF documents
- User Statistics: Tracks token usage and model selection per user
- Dockerized Deployment: Ready for easy deployment with Docker
- Automated CI/CD: Integrated with GitHub Actions
Prerequisites
To get started, ensure you have:
- Docker (for containerized deployment)
- Python 3.12.7
- Discord Bot Token
- OpenAI API Key
- Runware API Key (Get yours at Runware)
- Google API Key and Custom Search Engine ID (CX)
- MongoDB URL (Get from https://cloud.mongodb.com/)
Setup
For Normal Use
Option A: Deploy with Docker
-
Create a
.envfile in the root directory with your configuration:DISCORD_TOKEN=your_discord_token OPENAI_API_KEY=your_openai_api_key RUNWARE_API_KEY=your_runware_api_key GOOGLE_API_KEY=your_google_api_key GOOGLE_CX=your_google_cx OPENAI_BASE_URL=https://api.openai.com/v1/models MONGODB_URI=mongodb://localhost:27017/ ADMIN_ID=your_discord_user_id TIMEZONE=Asia/Ho_Chi_Minh -
Use the following
docker-compose.yml:version: '3.8' services: bot: image: ghcr.io/coder-vippro/chatgpt-discord-bot:latest env_file: - .env restart: always -
Start the bot with:
docker-compose up -d
Option B: Deploy Without Docker
-
Clone the repository:
git clone https://github.com/Coder-Vippro/ChatGPT-Discord-Bot.git cd ChatGPT-Discord-Bot -
Create a
.envfile in the root directory with your configuration:DISCORD_TOKEN=your_discord_token OPENAI_API_KEY=your_openai_api_key RUNWARE_API_KEY=your_runware_api_key GOOGLE_API_KEY=your_google_api_key GOOGLE_CX=your_google_cx OPENAI_BASE_URL=https://api.openai.com/v1/models MONGODB_URI=mongodb://localhost:27017/ ADMIN_ID=your_discord_user_id TIMEZONE=Asia/Ho_Chi_Minh -
Install the dependencies:
pip install -r requirements.txt -
Run the bot:
python3 bot.py
For Development
-
Clone the repository:
git clone https://github.com/Coder-Vippro/ChatGPT-Discord-Bot.git cd ChatGPT-Discord-Bot -
Install dependencies:
pip install -r requirements.txt -
Run the bot:
python3 bot.py
Running Tests
-
Install test dependencies:
pip install pytest -
Run tests:
pytest tests/
Usage
Once the bot is running, it connects to Discord using credentials from .env. Available features include:
Text Commands
- Normal chat: Ping the bot with a question or send a DM to start a conversation
- Image Generation:
/generate prompt: "A futuristic cityscape" - Web Content:
/web url: "https://example.com" - Google Search:
/search prompt: "latest news in Vietnam" - User Statistics:
/user_stat- Get your token usage and model information
Advanced Features
- Data Analysis: Upload CSV or Excel files for automatic analysis and visualization
- Code Execution: The bot can execute Python code to solve problems or create visualizations
- Reminders: Ask the bot to set reminders like "Remind me to check email in 30 minutes"
- PDF Analysis: Upload PDF documents for the bot to analyze and summarize
Available Models
The bot supports the following models:
- openai/gpt-4o
- openai/gpt-4o-mini
- openai/gpt-4.1
- openai/gpt-4.1-nano
- openai/gpt-4.1-mini
- openai/o1-preview
- openai/o1-mini
- openai/o1
- openai/o3-mini
- openai/o3
- openai/o4-mini
Environment Variables
| Variable | Description | Default |
|---|---|---|
| DISCORD_TOKEN | Your Discord bot token | Required |
| OPENAI_API_KEY | Your OpenAI API key | Required |
| RUNWARE_API_KEY | Runware API key for image generation | Required |
| GOOGLE_API_KEY | Google API key for search | Required |
| GOOGLE_CX | Google Custom Search Engine ID | Required |
| MONGODB_URI | MongoDB connection string | Required |
| ADMIN_ID | Discord user ID of the admin | Optional |
| TIMEZONE | Timezone for reminder feature | UTC |
| ENABLE_WEBHOOK_LOGGING | Enable webhook logging | False |
| LOGGING_WEBHOOK_URL | URL for webhook logging | Optional |
CI/CD
This project uses GitHub Actions for CI/CD, with workflows in .github/workflows.
Security
For supported versions and vulnerability reporting, see SECURITY.md.
Contributing
Please read our Code of Conduct before contributing to this project.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Made with ❤️ by coder-vippro