A Discord bot for the PyGreece online community that handles member onboarding and through a Code of Conduct acceptance flow. It also implements a ticket verification system.
- 👋 Automatically sends welcome messages to new members
- 📜 Implements a Code of Conduct acceptance workflow
- 🏷️ Assigns a role when members react to the Code of Conduct message
- 🚧 Handles ticket verification workflow
- 🎟️ Assigns a role when members submit their ticket IDs
- 🗄️ Tracks member status in a database
- 🐍 Python 3.12+
- 📚 discord.py library
- 🐘 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 Channels", "Manage Messages", "Manage Roles", "Manage Threads", "Send Messages", "Send Messages in Threads", from permissions
- Copy and paste the install link into your browser and invite the bot to your server
- Ensure the bot role is above the organizers and members roles 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>
ORGANIZER_ROLE_NAME=organizers
DATABASE_URL=postgresql+asyncpg://<username>:<password>@postgres/<db>
SPAM_COOLDOWN=<spam-cooldown-time-in-seconds>
MEMBER_ROLE_NAME=members
COC_MESSAGE_LINK=<message-link-of-code-of-conduct>
COC_THREAD_PREFIX=welcome
TICKET_HOLDER_ROLE_NAME=ticketholders
TICKET_MESSAGE_LINK=<message-link-of-ticket-message>
TICKET_THREAD_PREFIX=ticket
BOT_INTERACTIONS_CHANNEL_ID=<bot-interactions-channel-id>Use
compose.ymlto set DB credentials
-
Clone the repository
git clone https://github.com/pygreece/discord.git cd discord -
Install dependencies with
uvuv 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 -dbot/: Main bot code__main__.py: Entry pointmodals/: UI input formsticket_modal.py: Ticket verification UI input form
services/: Database insert logicticket_services.py: Ticket db insert logic
validations/: Validations checksticket_validation.py: Ticket validation check
views/: UI viewsbase_view.py: Base UI view with boilerplate logicticket_view.py: Ticket validation UI view
config.py: Configuration handlingdb.py: Database connection managementexceptions.py: Custom exceptionsmessages.py: Messages sent to members based on interactionsmodels.py: Database modelsroles.py: Role related functionssanitizers.py: String sanitizerssenders.py: Sends messages, creates and deletes the relevant private threadsticket_cog.py: Ticket verification systemutility_cog.py: Administration commands - main cogutility_tasks.py: Background taskswelcome_and_coc_cog.py: Actions related to new members joining
tests/: Test suitealembic/: Database migrations
Run the test suite:
uv run pytestRun 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.