This repo contains a simple Discord bot that uses OpenAI's GPT-3.5-turbo model to act as a chatbot while assuming a character. You can modify the code to use GPT-4 if you have access to it, but I have found that the turbo model is more than sufficient for this task.
- Create a Discord bot and invite it to your server. You can find a guide here. Make sure to enable the
Message Content
andServer Members
intents. - Create an OpenAI API key for the bot. You can find the API page here.
- Create a
.env
file in the root directory of the project and add the following lines:
OPENAI_API_KEY=<your openai api key>
DISCORD_BOT_TOKEN=<your discord bot token>
- Run
pip install -r requirements.txt
to install the dependencies. - Run
python bot.py
to start the bot.
- Summon the bot by mentioning it
- Follows a conversation via replies
- Each user has their own self-contained conversation
- User can reset the conversation by typing
forget me
The bot will automatically join the server and start listening for messages. To start a conversation, simply mention the bot then type your message. The bot will respond with a message that is generated by the API. You can then reply to the bot's message and the conversation will continue.
To make the bot reset the conversation, simply mention the bot and type forget me
.
For example: @GPTbot forget me
You can modify the code to use a different model or to change the character that the bot is acting as. To change the model, simply change the system_model
variable in bot.py
to the name of the model you want to use (e.g. gpt-4
).
To change the character, modify the system_prompt
variable in bot.py
to the name of the character you want the bot to act as.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
If you fork this repo, please follow the license, but more importantly, let me know what you're doing with it. I'd love to see what you come up with!
This project is licensed under the MIT License - see the LICENSE file for details