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 also has the ability to view and understand images, so that one or more images can be attached to the message. It's powered by OpenAI's ChatGPT models.
- Python 3.6 or above.
- An OpenAI API key.
- A Discord bot token.
Clone this repository:
git clone https://github.com/josantonius/chatgpt-discord-bot.git
Install the required Python packages:
pip install discord.py openai
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-4o",
"memory_characters": 120000,
"history_refresh_interval": 900,
"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.
history_refresh_interval
is the interval in seconds at which the chat context is refreshed.
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.
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!
The bot is summoned by mentioning it at the start of the message. For example:
@ChatGPT How are you?
It also has the ability to view and understand images, so that one or more images can be attached to the message.
The bot logs all messages and API calls for debugging purposes. The log is printed to the console.
- Add new feature
- Add tests
- Improve documentation
Detailed changes for each release are documented in the release notes.
Please make sure to read the Contributing Guide, before making a pull request, start a discussion or report a issue.
Thanks to all contributors! โค๏ธ
If this project helps you to reduce your development time, you can sponsor me to support my open source work ๐
This repository is licensed under the MIT License.
Copyright ยฉ 2023-present, Josantonius