ChatGPT Discord Bot
A bot designed for a small Discord channel among friends. This bot allows assigning a distinct personality to each user and maintaining the context of previous questions and answers. It's powered by OpenAI's ChatGPT models.
Requirements
- Python 3.6 or above.
- An OpenAI API key.
- A Discord bot token.
Installation
Clone this repository:
git clone https://github.com/josantonius/chatgpt-discord-bot.git
Install the required Python packages:
pip install discord.py openai
Configuration
Create a config.json
file in the root directory of the bot. This is an example of how the
configuration file should look like:
{
"model": "gpt-4",
"memory_characters": 8000,
"openai_api_key": "<Your OpenAI API key>",
"discord_token": "<Your Discord Bot Token>",
"presence": "The Lounge",
"context": [
{
"discord_name": "Evellyne",
"personality": "Evelyn is a seasoned data scientist. Interact in a polite and..."
},
{
"discord_name": "Sammy",
"personality": "Sam is a popular YouTube vlogger. Communicate in a cheerful and..."
},
{
"discord_name": "Morgan",
"personality": "Morgan is an NFT enthusiast. Respond to them with skepticism..."
}
],
"global_personality": "Maintain a cordial demeanor.",
"system_context": "You are an admin of a Discord channel assigned by Evelyn.",
"error_message": "Words fail me at the moment :/"
}
memory_characters
are the number of characters that the bot will remember from previous messages.
This value should not exceed the maximum number of tokens allowed by the model you are using.
Replace <Your OpenAI API key>
and <Your Discord Bot Token>
with your actual OpenAI API key and
Discord bot token respectively.
Each user in your Discord channel should have an entry in the context
array with their Discord
username and the personality you want the bot to use when interacting with them. If a user does not
have a specific entry, the bot will use the global_personality
.
The original names of Discord users are not sent to ChatGPT for privacy. Instead, the bot uses the
discord_name
field to identify users.
The system_context
is the initial context of the conversation with the bot.
Running the Bot
Once you have set up the configuration file, you can run the bot using Python:
python bot.py
Your bot should now be running and ready to interact with in your Discord server!
Commands
The bot is summoned by mentioning it at the start of the message. For example:
@ChatGPT How are you?
Logging
The bot logs all messages and API calls for debugging purposes. The log is printed to the console.
TODO
- Add new feature
- Add tests
- Improve documentation
Changelog
Detailed changes for each release are documented in the release notes.
Contribution
Please make sure to read the Contributing Guide, before making a pull request, start a discussion or report a issue.
Thanks to all contributors! ❤️
Sponsor
If this project helps you to reduce your development time, you can sponsor me to support my open source work 😊
License
This repository is licensed under the MIT License.
Copyright © 2023-present, Josantonius