A Discord bot template using discord.py that works very well for me. Discord bots can actually end up having a lot of boilerplate code for more serious Discord bot projects, so I've created this repository to help expedite that process of getting started.
- Python Poetry - This project uses Poetry as the package manager
- Python 3.11+ - Python 3.11 is the minimum supported version
- Docker Engine - Docker Engine is required if you plan on containerizing your Discord bot for deployment
- Discord Application - A Discord application (and a bot) is required. Make sure you have the token on hand.
- Click the "Use this template" button to use this template
- Clone the newly created repository locally using
git clone - Create an initial
.envwith your bot token:BOT_TOKEN=<YOUR BOT TOKEN HERE> - Install all dependencies using
poetry install --with dev - Activate the Poetry shell with
poetry shell - Run the bot using
python -m bot
Cogs and extensions should go in the bot/exts/ directory. All extensions MUST have a setup() function, or they will not be loaded. See here for more information.
Tests should go in the tests/ directory. This template uses pytest for automated tests.
Install pre-commit hooks using pre-commit install. It will now run on all git commits. This pre-commit is composed of tools like Black and Ruff which can each be configured under the [tool.black] and [tool.ruff] sections of pyproject.toml respectively. Feel free to customize and tweak these settings to your liking.
This template comes with a few GitHub Actions for building and publishing Docker images to the GitHub Container Registry, and linting and testing Python code on commits and pull requests.