This project requires python version 3.12.3 discord.py version 2.3.2, OpenAI version 1.30.1 and python-dotenv version 1.0.1 which can be installed via requirements.txt
:
pip install -r requirements.txt
pip install discord.py~=2.4.0
pip install openai~=1.61.0
pip install python-dotenv~=1.0.1
pip install requests~=2.32.3
- Create a
.env
file in the bot's root folder. (Same folder as main.py) - Format the
.env
file as follows, replacingTOKEN_HERE
,OWNER_UID_HERE
,CHAT_GPT_API_KEY_HERE
,OPENROUTER_DEEPSEEK_API_KEY
,DISCORD_SERVER_1
andDISCORD_SERVER_2
with your bot's token, your Discord UID, ChatGPT API key, openrouter api key and discord server ID's respectively. Keeping the double quotation marks.
BOT_TOKEN = "TOKEN_HERE"
OWNER_ID = "OWNER_UID_HERE"
GPT_API_KEY = "CHAT_GPT_API_KEY_HERE"
OPENROUTER_DEEPSEEK_API_KEY = "OPENROUTER_DEEPSEEK_API_KEY_HERE"
DISCORD_SERVER_1 = "FIRST_DISCORD_SERVER_ID_HERE"
DISCORD_SERVER_2 = "SECOND_DISCORD_SERVER_ID_HERE"
For example:
BOT_TOKEN = "12ab56c89"
OWNER_ID = "123456789"
GPT_API_KEY = "12ab56c89"
OPENROUTER_DEEPSEEK_API_KEY = "12ab56c89"
DISCORD_SERVER_1 = "123456789"
DISCORD_SERVER_2 = "123456789"
OWNER_ID
, DISCORD_SERVER_1
and DISCORD_SERVER_2
must be a numeric whole value
- The
.gitignore
file will ignore the.env
.
If you want to change the location of the .env
file, you will need to make a reference for it by adding:
dotenv_path = os.path.join("path/to/env", ".env")
above load_dotenv(override=True)
and update load_dotenv(override=True)
to:
load_dotenv(dotenv_path, override=True)
If you want to change your .env
file name as well add this reference to the .env
:
dotenv_path = os.path.join("path/to/env", "Env_Name_Here.env")
Open a new command line in the same folder as the main.py script (Make sure python is installed and/or your python venv is active) and type:
python main.py
- Visit to the discord developer portal applications page Here.
- Click the
New Application
button at the top right of the page next to your discord profile picture. - Name your application and click create. This will be used as the default username for your bot.
- Navigate to the
Bot
page on the left navigation pannel as shown below:
- Change your bot's username under
USERNAME
if desired. - Click the
Reset Token
button and copy your bots token for use in the.env
file. You will have to reset the bot token to view and copy it again. - Navigate to the
OAuth2
page on the left navigation pannel as shown below:
- Select
bot
underOAuth2 URL Generator
SCOPES
and selectAdministrator
underBOT PERMISSIONS
GENERAL PERMISSIONS
. - Copy the generated discord link under
GENERATED URL
at the bottom of the page and paste this link into your web browsers address bar. - Follow the prompts to add your bot to any discord server where you have the
Manage Server
orAdministrator
permission.
- On Discord, go to Settings > Advanced
- Scroll down and make sure that Developer Mode is on
- Exit settings and left click on your profile picture at the bottom left of discord (same place as the settings button) and click
Copy User ID
as shown below:
- On Discord, go to Settings > Advanced
- Scroll down and make sure that Developer Mode is on
- Exit settings and right click on the server(s) your bot is in
and click
Copy Server ID
as shown below:
- Visit the openai playground website settings page Here.
- Click the
Create Project
button at the bottom of the settings list as shown below:
- Name your project and click the
Create
button. - Navigate to the
API keys
page above the settings page on the left side navigation pannel. Alternatively you can click Here. - Click the
Create new secret key
button. - Choose
You
underOwned by
. Name your API key something descriptive and select the new project you just created in theProject
dropdown. SetPermissions
asAll
and click theCreate secret key
button as shown below:
Ensure you have an available Credit balance
. You can check on the Billing
page in Settings
or by clicking Here. If you do not have a Credit balance
you will need to add money (credit) to your account otherwise this discord bot's chat GPT functionality will not work.
as DeepSeek's api is currently down you will have to use OpenRouter to access the DeepSeek AI. Ensure you have selected the free DeepSeek-R1 model on Openrouter
.
- navigate to the openrouter API key page.
- Click the
Create Key
button.