/discord-bot-template

Discord Bot Template / Boilerplate

Primary LanguagePythonGNU General Public License v3.0GPL-3.0

Discord Bot Template

Tests

Discord bot with slash commands. It uses MongoDB database and disnake Discord API wrapper.

Requirements

How to use this template

To use this template as your project starting point, click "Use this template" at the top of this page, or click here.

Feature highlights

  • Asynchronous support for files (via aiofiles), HTTP requests (via aiohttp), and MongoDB drivers (via motor & Beanie)
  • Environment configuration with python-dotenv
  • Logs via loguru
  • Error handling
  • Docker image build workflow to push images to Docker Hub
  • Temporary file directory with scheduled clean-up

Project structure

├── requirements.txt
├── bot.py              # The `MyBot` class
├── launcher.py         # Entry point to launch the bot
├── .env                # Environment variables for bot configuration (renamed from .env.example)
├── cogs
│   ├── admin.py        # Slash commands for guild administrators
│   ├── commands.py     # Example cog with some example slash commands
│   ├── events.py       # Discord event listeners
│   ├── owner.py        # Slash commands for the bot owner only
│   └── tasks.py        # Disnake scheduled background tasks
├── helpers
│   ├── __init__.py
│   ├── embeds.py       # Common Discord embed templates
│   └── utilities.py    # General utilities
├── models
│   ├── __init__.py
│   ├── guild.py        # Example ODM model for guilds
│   └── settings.py     # ODM model for global bot settings
├── views
│   ├── __init__.py
│   └── paginator.py    # Example view implementing embed pages
├── Dockerfile
├── README.md
├── DEVELOPMENT.md
└── LICENSE

Todo

  • Tests with pytest
  • CI based on Github actions
  • Dependabot configuration
  • Instructions to create bot application with correct permissions
  • Dockerfile
  • Instructions to set up docker hub secrets in Github

Contributing

Contributors are welcome, please fork and send pull requests! If you find a bug or have any ideas on how to improve this project please submit an issue.

Development

Code formatting

ruff is used for code formatting. Always format the code with ruff before submitting a pull request.

Testing

# Inside the project root (directory containing this file)
python -m venv venv && source ./venv/bin/activate
pip install -r requirements.txt
pip install -r requirements-test.txt
mypy
pytest
ruff format .