ChatGPT Discord Bot
Build your own Discord bot using ChatGPT
Warning
2023-02-10 Update: ChatGPT model but requires payment
2023-02-08 Update: ChatGPT API is highly unstable now
2023-02-03 Update: ChatGPT API working again
2023-02-02 Update: OpenAI has closed ChatGPT API, temporarily switching to using GPT-3 model
2023-02-01 Update: Now using the official ChatGPT API
Features
/chat [message]
Chat with ChatGPT!/private
ChatGPT switch to private mode/public
ChatGPT switch to public mode/replyall
ChatGPT switch between replyall mode and default mode/reset
Clear ChatGPT conversation history
Chat
Mode
-
public mode (default)
the bot directly reply on the channel -
private mode
the bot's reply can only be seen by the person who used the command -
replyall mode
the bot will reply to all messages in the server without using slash commandsWarning The bot will easily be triggered in
replyall
mode, which could cause program failures
Setup
Install
pip install -r requirements.txt
- Rename the file
.env.dev
to.env
Step 1: Create a Discord bot
-
Go to https://discord.com/developers/applications create an application
-
Build a Discord bot under the application
-
Get the token from bot setting
-
Store the token to
.env
under theDISCORD_BOT_TOKEN
-
Turn MESSAGE CONTENT INTENT
ON
-
Invite your bot to your server via OAuth2 URL Generator
Step 2: Generate a OpenAI API key
-
Click Create new secret key
-
Store the SECRET KEY to
.env
under theOPENAI_KEY
Step 3: Run the bot on the desktop
- Open a terminal or command prompt
- Navigate to the directory where you installed the ChatGPT Discord bot
- Run
python3 main.py
to start the bot
Step 3: Run the bot with Docker
-
Build the Docker image & Run the Docker container
docker compose up -d
-
Inspect whether the bot works well
docker logs -t chatgpt-discord-bot
Stop the bot:
docker ps
to see the list of running servicesdocker stop <BOT CONTAINER ID>
to stop the running bot
Have a good chat!
Optional: Setup starting prompt
-
A starting prompt would be invoked when the bot is first started or reset
-
You can set it up by modifying the content in
starting-prompt.txt
-
All the text in the file will be fired as a prompt to the bot
-
Get the first message from ChatGPT in your discord channel!