Zero6992/chatGPT-discord-bot
PythonIntegrate ChatGPT into your own discord bot
pip install chatgpt-discord-botChatGPT Discord Bot
Build your own Discord bot with multiple AI providers
[!IMPORTANT]
Major Refactor (2025/07):
- 5 AI Providers: Free (g4f), OpenAI, Claude, Gemini, Grok
- No Cookie Authentication: Removed unreliable cookie-based auth for free providers
Chat

Setup
Prerequisites
- Python 3.9 or later
- Rename the file
.env.exampleto.env - Running
pip3 install -r requirements.txtto install the required dependencies - Optional: API keys for premium providers (OpenAI, Claude, Gemini, Grok)
Step 1: Create a Discord bot
Go to https://discord.com/developers/applications create an application
Build a Discord bot under the application
Get the token from bot setting

Store the token to
.envunder theDISCORD_BOT_TOKEN
Turn MESSAGE CONTENT INTENT
ON
Invite your bot to your server via OAuth2 URL Generator

Step 2: Run the bot on the desktop
Open a terminal or command prompt
Navigate to the directory where you installed the ChatGPT Discord bot
Run
python3 main.pyorpython main.pyto run the bot
Step 2: Run the bot with Docker
Build the Docker image & run the Docker container with
docker compose up -dInspect whether the bot works well
docker logs -t chatgpt-discord-botStop the bot:
docker psto see the list of running servicesdocker stop <BOT CONTAINER ID>to stop the running bot
Have a good chat!
Provider Configuration
Free Provider (unstable)
Outdated model, close to GPT-3.5 or GPT-4 capabilities
No configuration required
Premium Providers (Optional)
OpenAI
- Obtain your API key from https://platform.openai.com/api-keys
- Add to
.env:OPENAI_KEY=your_api_key_here
Claude (Anthropic)
- Get API key from https://console.anthropic.com/
- Add to
.env:CLAUDE_KEY=your_api_key_here
Gemini (Google)
- Get API key from https://ai.google.dev/
- Add to
.env:GEMINI_KEY=your_api_key_here
Grok (xAI)
- Get API key from https://x.ai/api
- Add to
.env:GROK_KEY=your_api_key_here
Use /provider command in Discord to switch between available providers
Image Generation

Image generation is now integrated with the provider system:
OpenAI DALL-E 3
- Requires OpenAI API key
- High-quality image generation
- Use
/draw [prompt] openai
Google Gemini
- Requires Gemini API key
- Free tier available
- Use
/draw [prompt] gemini
Fallback Options
- If premium providers are unavailable, the bot will attempt to use free alternatives
- Image generation capabilities vary by provider availability
Optional: Setup system prompt
A system prompt would be invoked when the bot is first started or reset
You can set it up by modifying the content in
system_prompt.txtAll the text in the file will be fired as a prompt to the bot
Get the first message from ChatGPT in your discord channel!
Go Discord setting turn
developer modeonRight-click the channel you want to recieve the message,
Copy IDpaste it into
.envunderDISCORD_CHANNEL_ID
Optional: Disable logging
- Set the value of
LOGGINGin the.envto False
Commands
Core Commands
/chat [message]- Chat with the current AI provider/provider- Switch between AI providers (Free, OpenAI, Claude, Gemini, Grok)/draw [prompt] [model]- Generate images with specified provider/reset- Clear conversation history/help- Display all available commands
Persona Commands
/switchpersona [persona]- Switch AI personality (admin-only for jailbreaks)standard- Standard helpful assistantcreative- More creative and imaginative responsestechnical- Technical and precise responsescasual- Casual and friendly tonejailbreak-v1- BYPASS mode (admin only)jailbreak-v2- SAM mode (admin only)jailbreak-v3- Developer Mode Plus (admin only)
Bot Behavior
/private- Bot replies only visible to command user/public- Bot replies visible to everyone (default)/replyall- Bot responds to all messages in channel (toggle)
Security Features
Admin-Only Jailbreak Access
Jailbreak personas require admin privileges for enhanced security:
- Set
ADMIN_USER_IDSin.envwith comma-separated Discord user IDs - Only admin users can access jailbreak personas
- Regular users see only safe personas in
/switchpersona
Warning Jailbreak personas may generate content that bypasses normal AI safety measures. Admin access required.
Environment Security
- No cookie-based authentication (removed for reliability)
- Secure API key management via environment variables
- Docker security hardening with non-root user
- Read-only filesystem for container security