a discord.py bot template that I use for my bots.
you're free to use this template if you like.
You should have received a copy of the LICENSE file with this source code.
This source code is licensed under the MIT License.
Note
Python 3.10+ should work with this bot. However it is recommended to use the latest Python 3.13 version.
Visual Studio Code extensions skip?
This bot was created, developed and meant to be used with the Visual Studio Code IDE. I have listed the recommended extensions for this bot to be used with Visual Studio Code below.
- autoDocstring (by Nils Werner)
- Better Color Picker (by Jannchie)
- Black Formatter (by Microsoft)
- Error lens (by Alexander)
- GitHub Markdown Preview [Extension Pack] (by Matt Bierner)
- Markdown Preview GitHub Styling (by Matt Bierner)
- Markdown Emoji (by Matt Bierner)
- Markdown Checkboxes (by Matt Bierner)
- Markdown yaml Preamble (by Matt Bierner)
- Markdown Footnotes (by Matt Bierner)
- Markdown Preview Mermaid Support (by Matt Bierner)
- Local History (by xyz)
- Prisma (by Prisma)
- Pylance (by Microsoft)
- Python (by Microsoft)
- Python Debugger (by Microsoft)
- Python Environments (by Microsoft)
- Python Indent (by Kevin Rose)
- SQLite3 Editor (by yy0931)
- :emojisense: (by Matt Bierner)
- AmazonQ (by Amazon Web Services)
- Even Better TOML (by tamasfe)
- Hex Editor (by Microsoft)
- Live Share (by Microsoft)
- Rainbow CSV (by mechatroner)
- Remote - SSH (by Microsoft)
- Discord Rich Presence (by leonardssh)
- Material Icon Theme (by Philipp Kief)
- One Dark Pro (by binaryify) (I use this rarely)
- Vitesse Theme (Anthony Fu) (I use this one the most)
Setting up a new project skip?
First of all, git clone this repository:
git clone git@github.com:sqdnoises/discord.py-bot-template.git # SSH
git clone https://github.com/sqdnoises/discord.py-bot-template.git # HTTPSThen reinitialize git .git (recommended to do this if you are starting a new project)
rm -rf .git # Linux
git init
git branch -M mainSet the remote for a new project.
git remote add origin git@github.com:user/repo.git # SSH
git remote add origin https://github.com/user/repo.git # HTTPSMake sure to replace user with your GitHub username and repo with your repository name.
Copy or rename the .env.example file to .env and configure .env appropriately.
This file contains secret environmental variables that are not meant to be shared with anyone.
You must configure the TOKEN and DATABASE_URL variable. Review other variables in the file for optional configurations.
Installation instructions here
(tl;dr: you can use pip install uv)
$ uv python install 3.13
Searching for Python versions matching: Python 3.13
Installed 1 version in 3.13s
+ cpython-3.13.2-windows-x86_64-none$ uv venv
Using CPython 3.13.2
Creating virtual environment at: .venv
Activate with: source .venv/bin/activateRun the shown venv activation command after the command is executed.
$ uv pip install -r requirements.txt
Resolved 44 packages in 5.11s
Prepared 44 packages in 1m 50s
Installed 44 packages in 81ms
+ aiohappyeyeballs==2.6.1
+ aiohttp==3.11.13
...$ prisma db push
Environment variables loaded from .env
Prisma schema loaded from prisma\schema.prisma
Datasource "db": SQLite database "database.db" at "file:../database/database.db"
SQLite database database.db created at file:../database/database.db
Your database is now in sync with your Prisma schema. Done in 57ms
✔ Generated Prisma Client Python (v0.15.0) to .venv/lib/site-packages/prisma in 394msOpen src/config.py in the editor of your choice and edit the config variables as needed.
Make sure you update ADMINS and LOG_CHANNEL to the appropriate values.
make sure your venv is activated and run:
python3 -m src # py -m src/python -m src on Windowsmake sure docker is installed on your device/server and run:
docker compose up --buildor to run it detached:
docker compose up --build -dSince the bot's profile has been set up for the first time, you need to tell Discord that your bot has slash commands.
For this you need to use !sync in a server the bot is in after running the bot for the first time.
This will synchronise all the slash commands in the code on Discord. Please restart your Discord app after this step to refetch all slash commands and then it should show the bot's slash commands when you start typing with / in a server the bot is in or anywhere if installed as an user app.
If you host the bot on linux and use the /ping command, you will likely see the bot think forever or produce an error and see an Permission Error error in the console.
Linux uses a kernel parameter that restricts who can create ping sockets.
For troubleshooting, please refer to: kyan001/ping3/TROUBLESHOOTING.md
© 2023-present SqdNoises
Licensed under the MIT License.