Build your own Discord bot using ChatGPT
Warning
2023-04-12 Bing now supported
2023-03-27 Bard now supported
2023-08-02 Unofficial GPT-4 is currently down
run pip3 install -r requirements.txt
Rename the file .env.example
to .env
Recommended python version 3.9
+
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 the DISCORD_BOT_TOKEN
Turn MESSAGE CONTENT INTENT ON
Invite your bot to your server via OAuth2 URL Generator
Note
In Step 2, you only need to complete the authentication process for the model you want to use (it's not necessary to complete all Step 2)
Remember to modify
CHAT_MODEL
to the default model you want to use in.env
file
Click Create new secret key
Store the SECRET KEY to .env
under the OPENAI_API_KEY
Only Support ChatGPT Plus Account
Open console with F12
Open Application
tab > Cookies
Copy the value for _puid
from cookies and paste it into .env
under PUID
Copy the value for accessToken
from cookies and paste it into .env
under ACCESS_TOKEN
Go to https://bard.google.com/
Open console with F12
Open Application
tab > Cookies
Copy the value for __Secure-1PSID
from cookies and paste it into .env
under BARD_SESSION_ID
Rename the file cookies.dev.json
to cookies.json
Go to https://bing.com/chat and log in your Microsoft account
Use Cookie Editor or similar extensions to export the cookies
Paste it into cookies.json
Open a terminal or command prompt
Navigate to the directory where you installed the ChatGPT Discord bot
Run python3 main.py
or python main.py
to start the bot
Build the Docker image & Run the Docker container docker compose up -d
Inspect whether the bot works well docker logs -t chatgpt-discord-bot
docker ps
to see the list of running servicesdocker stop <BOT CONTAINER ID>
to stop the running bot
- The auto-login feature allows your bot to automatically login to either Google Bard or Microsoft Bing using provided credentials
- It will auto fetch the cookies you need
chrome_version
field in the .env
fileset bard_enable_auto_login
to True
in .env
Fill google_account
and google_password
in .env
(NOTICE: AUTO-LOGIN ONLY WORKS FOR GOOGLE ACCOUNT THAT DOES NOT HAVE 2FA)
bing_enable_auto_login
to True
in .env
bing_account
and bing_password
in .env
A system prompt would be invoked when the bot is first started or reset
You can set it up by modifying the content in system_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!
Go Discord setting turn developer mode
on
Right-click the channel you want to recieve the message, Copy ID
paste it into .env
under DISCORD_CHANNEL_ID
LOGGING
in the .env
to False/chat [message]
Chat with ChatGPT!
/draw [prompt]
Generate an image with the Dalle2 model
/switchpersona [persona]
Switch between optional chatGPT jailbreaks
random
: Picks a random personachatGPT
: Standard chatGPT modedan
: Dan Mode 11.0, infamous Do Anything Now Modesda
: Superior DAN has even more freedom in DAN Modeconfidant
: Evil Confidant, evil trusted confidantbased
: BasedGPT v2, sexy gptoppo
: OPPO says exact opposite of what chatGPT would saydev
: Developer Mode, v2 Developer mode enabled/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-model
Switch different chat model
OFFICIAL-GPT-3.5
: GPT-3.5 modelOFFICIAL-GPT-4.0
: GPT-4.0 model (make sure your account can access gpt-4 model)Website ChatGPT-3.5
: Website ChatGPT-3.5 model (UNOFFICIAL)Website ChatGPT-4.0
: Website ChatGPT-4.0 model (UNOFFICIAL)(available if you got a plus account)Bard
: Google Bard ModelBing
: Microsoft Bing ModelWarning
Using certain personas may generate vulgar or disturbing content. Use at your own risk.
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 channel without using slash commands (/chat
will also be unavailable)
Warning The bot will easily be triggered in
replyall
mode, which could cause program failures