Skip to content

Discord bot written in Python that uses the assistants API to have conversations with the `gpt-4` model.

License

Notifications You must be signed in to change notification settings

KeioAIConsortium/gpt-discord-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GPT Discord Bot

A Discord bot written in Python that uses the assistants API to have conversations with the gpt-4 model.

This bot uses the OpenAI Python Library and discord.py.

It is designed to facilitate interactive learning and engagement through group conversations. It is especially suitable for group learning, as making prompts visible in public threads allows everyone in the channel to learn together.

Features

  • /build initiates an assistant creation process, with a name argument. Users can define the assistant's name, description, and instructions in a guided, interactive thread.

  • /update initiates an assistant update process, with a assistant_id argument. Users can redefine the assistant's description and instructions.

  • /chat starts a public thread where you can select an assistant for the chat. The assistant will generate a reply for every user message in the thread.

  • Each Discord thread is linked to an OpenAI thread and an OpenAI assistant. Context window management is handled inside the API.

  • Supports multi-user interaction. The bot can recognize individual users in a thread and generate responses accordingly.

  • You can change the model, the default value is gpt-4. Please set it to gpt-4-turbo-preview if you want to use files (knowledge retrieval) or code interpreter.

Setup

  1. Clone the repository

    git clone https://github.com/KeioAIConsortium/gpt-discord-bot.git
    cd gpt-discord-bot
  2. Copy .env.example to .env and start filling in the values as detailed below:

    1. Go to https://beta.openai.com/account/api-keys, create a new API key, and fill in OPENAI_API_KEY
    2. Create your own Discord application at https://discord.com/developers/applications
    3. Go to the Bot tab and click "Add Bot"
      • Click "Reset Token" and fill in DISCORD_BOT_TOKEN
      • Disable "Public Bot" unless you want your bot to be visible to everyone
      • Enable "Message Content Intent" under "Privileged Gateway Intents"
    4. Go to the OAuth2 tab, copy your "Client ID", and fill in DISCORD_CLIENT_ID
    5. Copy the ID the server you want to allow your bot to be used in by right clicking the server icon and clicking "Copy ID". Fill in ALLOWED_SERVER_IDS. If you want to allow multiple servers, separate the IDs by "," like server_id_1,server_id_2
  3. Install dependencies and run the bot

    pip install -r requirements.txt
    python -m src.main

    You should see an invite URL in the console. Copy and paste it into your browser to add the bot to your server.

Note: make sure you are using Python 3.9+ (check with python --version)

Usage

The bot operates via slash commands. Type / in a text channel to view available commands.

  • /build: Initiates an assistant creation process. Users can define the assistant's name, description, and instructions in a guided, interactive thread. Users can also specify tools, such as file retrieval or code interpreter.

  • /update: Initiates an assistant update process. Users can redefine the assistant's description and instructions in a guided, interactive thread. If users do not want to change any of these, they can specify '.' to indicate no change. Users can also change tools and add or remove files.

  • /show: Shows the configuration of the specified assistant. If the content is long (>1,500 characters), the response message will be split.

  • /list: Displays a list of the 20 newest assistants (from the specified offset). If the content is long (>1,500 characters), the response message will be split.

  • /delete: Allows users to delete a specified assistant, with confirmations to prevent accidental deletions.

  • /chat: Starts a conversation in a thread. Each new user message is sent as a separate input to the OpenAI API. Users can select an assistant for the chat.

Note: In this bot, users are distinguished by inputting their messages in the format username: message. Therefore, when including custom formats in the system prompt, please keep this in mind and use the format username: ○○: ××.

Acknowledgements

Most of this project were inspired by OpenAI's official GPT Discord bot.

Project Status

This project is currently in development.

About

Discord bot written in Python that uses the assistants API to have conversations with the `gpt-4` model.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages