A Discord bot for the PyGreece online community that handles member onboarding through a Code of Conduct acceptance flow.
- 👋 Automatically sends welcome messages to new members
- 📜 Implements a Code of Conduct acceptance workflow
- 🏷️ Assigns roles when members react to the Code of Conduct message
- 🗄️ Tracks member status in a database
- 🐍 Python 3.12+
- 🐘 PostgreSQL database (for production)
- 🔑 Discord Bot Token
- Go to the Discord Developer Portal
- Create a new application
- Go to the "Bot" tab and create a bot
- Enable the "Server Members Intent" and "Message Content Intent" under Privileged Gateway Intents
- Save the bot token for configuration
- Go to the "Installation" tab and choose the "bot" option on the applications.commands dropdown for Guild Install
- Select "Manage Roles" from permissions
- Copy and paste the install link into your browser and invite the bot your server
- Ensure the bot role is above the members role in the role hierarchy
This bot is used as a public bot in a Guild Install, private bot mode and user install will need testing
Copy .env.sample
to a new file called .env
and update the placeholder values:
DISCORD_TOKEN=<your-discord-bot-token>
DISCORD_GUILD=<your-discord-server-name>
DATABASE_URL=postgresql+asyncpg://<username>:<password>@postgres/<db>
MEMBER_ROLE_NAME=members
COC_MESSAGE_ID=<message-id-of-code-of-conduct>
COC_MESSAGE_LINK=<message-link-of-code-of-conduct>
Use
compose.yml
to set DB credentials
-
Clone the repository
git clone https://github.com/pygreece/discord.git cd discord
-
Install dependencies with
uv
uv venv source .venv/bin/activate # On Windows use: .venv\Scripts\activate uv sync
The project includes Docker configuration for easy local deployment:
docker-compose up -d
bot/
: Main bot code__main__.py
: Entry pointcog.py
: Core bot functionalitymodels.py
: Database modelsdb.py
: Database connection managementconfig.py
: Configuration handlingexceptions.py
: Custom exceptions
tests/
: Test suitealembic/
: Database migrations
Run the test suite:
uv run pytest
Run with coverage:
uv run pytest --cov
- Fork the repository
- Create a feature branch
git checkout -b feature/your-feature-name
- Make your changes
- Run tests and make sure they pass ✅
- Push your branch and create a pull request
This project follows the PyGreece code of conduct. Please be respectful and inclusive when contributing to this project.