Python discord bot
This is a discord bot written in discord.py. It has a flask backend so the bot can be configured through a web interface (coming soon™️)
- Set up your
.env
file, this stores all credentials/tokens that should not be checked into git. You can look atexample.env
for reference- Copy your Discord bot token into the
DISCORD_ID
field (you can find/make a bot here) - setup all other environment variables as needed
- look at
bot/src/config.yml
and set any settings to what you want
- Copy your Discord bot token into the
- Set
BOT_API_TOKEN
in.env
to a random string, you can run the following to generate oneuse the same process to setimport secrets print(secrets.token_urlsafe())
FLASK_SECRET_KEY
- Install docker and docker-compose https://docs.docker.com/compose/install/
- Run
docker-compose up
- Add the bot to your server:
- go to the discord application page
- select your application and go to "OAuth2"
- select the "bot" checkbox under "Scopes" and go to the link provided underneath
- select the discord server to add the bot to
- type "?help" into chat
While this uses docker to run the bot and flask backend, you can make a conda environment so your ide (vsCode) can have autocomplete for the packages.
conda create -n thiccBot python=3.7 pip
source activate thiccBot
cd bot
pip install -r requirements.txt
cd ..
cd backend
pip install -r requirements.txt
docker-compose up
if you want to run the web interface locally you can do
docker-compose up
# in a different tab
./runWeb.sh
Run the following command when ever you change or add a model. Not all changes will be detected so look over the generated scripts. More info here
docker-compose run flask flask db migrate
After looking over the scripts and it looks good run
docker-compose run flask flask db upgrade
If you are starting with a fresh container after changing models first build and run everything then run docker-compose run flask flask db migrate
If the db has data and the migration thinks the db is not on the latest migration version run
docker-compose run flask flask db stamp <last revision>
to get things working
docker-compose -f docker-compose.prod.yml run pgbackups /backup.sh
source .env
docker exec -it thiccbot_postgres_1 psql -U $THICC_USER -w $THICC_PASSWORD -d $THICC_DB
if you need to restore a backup first wipe the folder ./postgres-data
then run
# run just pg so flask and bot don't start putting stuff in the db
docker-compose -f docker-compose.prod.yml run -d postgres
source .env
cat <backup_dump.sql> | docker exec -i <pg_container_id> psql -U $THICC_USER -w $THICC_PASSWORD -d $THICC_DB
Use the python formatter black, install it with pip install black
.