A Discord bot I'm making to help me practice coding! :)
Use the following command to upgrade packages in requirements.txt
:
pip install -U -r requirements.txt
These instructions are mostly for myself, so I can remember how to re-install the project.
After cloning the repo, create a virtual environment and activate it:
python3 -m venv .venv
source .venv/bin/activate
Now you can install the packages using the requirements file:
pip install -r requirements.txt
The following command creates a .env
file containing our environment variables:
echo -e "DISCORD_TOKEN=" >> .env
Head to https://discord.com/developers/applications and Create a New Application.
After creating your application, head to the Bot tab and create a new bot.
Then add the bot to a server using the OAuth2 tab, scroll down to scopes, check bot and visit the generated URL.
DISCORD_TOKEN
can be found in the Bot tab. Copy it and append to our.env
file.
To run the script for the bot, simply run
python3 bot.py
I use PM2 to run the bot as a process in the background.
To install PM2:
npm install -g pm2
In the project directory, start the bot:
pm2 start bot.py --interpreter=/usr/bin/python3
pm2 list list all pm2 processes
pm2 stop bot.py stop the bot
pm2 restart bot.py restart the bot
When starting the bot for the first time, if you get the following error:
ModuleNotFoundError: No module named 'discord'
Run the command:
pm2 start bot.py --interpreter python3 --interpreter-args -u
This will flush everything [Stackoverflow].