# GPTDiscord

> A self-hosted OpenAI bot for Discord — ChatGPT-style threads, image understanding, DALL-E, code execution, document Q&A and AI moderation behind slash commands

- Category: Agents & Automation / Assistants & Chatbots
- Language: Python
- Licence: MIT
- Repository: https://github.com/Kav-K/GPTDiscord
- Canonical page: https://ai-tldr.dev/tools/gptdiscord/
- Updated: 2026-02-06

## In short

GPTDiscord is an open-source Python bot that puts OpenAI's models inside a Discord server. It sits in the Assistants & Chatbots category of the Agents & Automation tools and is open-source, written in Python and licensed MIT. To get started: clone the project.

## Overview

GPTDiscord is an open-source Python bot that puts OpenAI's models inside a Discord server. You run it yourself with your own OpenAI API key and Discord bot token, and members reach it through grouped slash commands: /gpt converse opens a ChatGPT-style conversation in a thread or a whole channel, /gpt ask answers a one-off prompt, and you can simply tag the bot in chat for a reply. Conversations can include images the bot looks at, and it can draw with DALL-E inside the same exchange.

Beyond chat, the bot bundles several specialised modes. /code chat is a code-interpreter conversation that runs Python in an isolated execution environment (the project credits E2B for code execution), with the ability to install packages and reach the internet. /internet chat and /internet search connect the model to Google, Wolfram Alpha and a web crawler. The /index commands build custom indexes from uploaded files, links or Discord channel history, so the bot can answer from your own documents; the project is moving its vector storage from Pinecone to Qdrant.

Server-management features sit alongside the AI ones: automatic AI moderation with an alert channel, DeepL translation, role-based permissions for GPT, DALL-E and admin commands, per-user and per-channel system instructions, optional per-user API keys, token-usage tracking and a low-usage mode that switches to a cheaper model. Everything is configured through a single .env file, and the bot can be run directly with Python, in Docker, or with Docker Compose.

## What it does

- ChatGPT-style conversations in threads or channels with /gpt converse, including image understanding and in-conversation DALL-E drawing
- Code interpreter mode (/code chat) that executes Python in an isolated environment and can install packages
- Internet-connected chat and search backed by Google, Wolfram Alpha and a link crawler
- Custom indexes for document Q&A from uploaded files, links or Discord channel history (/index add, /index chat, /index discord_backup)
- DALL-E image generation plus a prompt optimizer, and DeepL translation
- AI moderation, role-based command permissions, per-user and per-channel instructions, and optional user-supplied API keys
- Operational controls in Discord: model settings such as temperature and top_p, usage tracking, low-usage mode and a debug channel for raw responses

## Getting started

You need an OpenAI API key and a Discord bot token (create an application in the Discord Developer Portal, enable its intents and invite it with the bot and applications.commands scopes). The project recommends Python 3.9.

1. Clone the project

```bash
git clone https://github.com/Kav-K/GPTDiscord.git
cd GPTDiscord/
```

2. Install the dependencies

   The torch and whisper packages power OCR/document features and audio extraction for indexing .mp3 and .mp4 files.

```bash
python3.9 -m venv venv
source venv/bin/activate
python3.9 -m pip install torch==1.13.1+cpu torchvision==0.14.1+cpu -f https://download.pytorch.org/whl/torch_stable.html
python3.9 -m pip install git+https://github.com/openai/whisper.git
python3.9 -m pip install -r requirements.txt
python3.9 -m pip install .
```

3. Configure the .env file

   Copy the sample and fill in at least OPENAI_TOKEN, DISCORD_TOKEN, DEBUG_GUILD, DEBUG_CHANNEL and ALLOWED_GUILDS. Guild and channel IDs come from right-clicking a server or channel in Discord and choosing Copy ID. Role lists such as ADMIN_ROLES, DALLE_ROLES and GPT_ROLES control who can use which commands.

```bash
cp sample.env .env
nano .env
```

4. Run the bot

```bash
python3.9 gpt3discord.py
```

5. Or run it in Docker

   Mount your .env file to /opt/gpt3discord/etc/environment and add DATA_DIR=/data and SHARE_DIR=/data/share to it. A docker-compose.yml is also provided: fill in .env and run docker-compose up -d.

```bash
docker run -d --name gpt3discord -v env_file:/opt/gpt3discord/etc/environment -v /containers/gpt3discord:/data -v /containers/gpt3discord/share:/data/share ghcr.io/kav-k/gptdiscord:main-full
```

## When to use it

- Give a Discord community a shared ChatGPT-style assistant that runs on your own OpenAI key, with roles deciding who can use it
- Let members ask questions over uploaded documents, links or a server's own channel history
- Run Python analysis or web-connected research without leaving Discord
- Add automatic AI moderation and translation to a busy server

## Version history

- 2026-02-06 v12.4.0: Migrated the bot to OpenAI's Chat Completions API and updated dependencies.
