A production-ready Discord bot named "Patchy" that receives GitHub webhook events and sends beautifully formatted notifications to your Discord server. Built with Python, FastAPI, and discord.py.
- π Real-time Notifications: Get instant Discord notifications for GitHub events
- π¨ Beautiful Embeds: Rich, formatted messages with colors, links, and detailed information
- π Secure: GitHub webhook signature verification for security
- π Comprehensive Event Support: Push, Pull Requests, Issues, Releases, Branch/Tag creation/deletion
- π‘οΈ Production Ready: Comprehensive error handling, logging, and monitoring
- π’ Easy Deployment: Ready for Render (Docker), Railway, Vercel (serverless), and Docker
- π° Cost-Effective: Free tier options available for internal use
This project is organized into a clean structure:
discord-bot/
βββ π Core Files (Essential) # Main application files
βββ οΏ½ Docker Files (Important) # Container setup & orchestration
βββ οΏ½π docs/ # Documentation guides
βββ π οΈ dev-tools/ # Testing & development utilities
βββ π¦ optional/ # Alternative deployments
βββ deployments/ # Vercel, Render, etc.
π See STRUCTURE.md for detailed information about the project organization.
- Push Events: New commits with author info and commit messages
- Pull Requests: Open, close, merge, and reopen events
- Issues: Open, close, and reopen with labels
- Releases: New releases with descriptions and download links
- Create/Delete: Branch and tag creation/deletion events
- Python 3.11 or higher
- A Discord server where you have admin permissions
- A GitHub repository
- A hosting service (Railway, Render, Heroku, or your own server)
- Go to the Discord Developer Portal
- Click "New Application" and give it a name
- Go to the "Bot" section and click "Add Bot"
- Copy the bot token (you'll need this later)
- Under "Privileged Gateway Intents", enable "Message Content Intent"
- Go to "OAuth2" β "URL Generator"
- Select "bot" scope and "Send Messages" permission
- Use the generated URL to invite the bot to your server
- Enable Developer Mode in Discord (User Settings β Advanced β Developer Mode)
- Right-click on the channel where you want notifications
- Click "Copy ID"
- Go to your GitHub repository
- Navigate to Settings β Webhooks β Add webhook
- Set the Payload URL to:
https://your-domain.com/webhook - Set Content type to:
application/json - Generate a webhook secret (save this!)
- Select events: Push, Pull requests, Issues, Releases, Create, Delete
- Click "Add webhook"
-
Clone and setup:
git clone <your-repo-url> cd discord-bot python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate pip install -r requirements.txt
-
Configure environment:
cp env.example .env # Edit .env with your tokens and IDs -
Run the bot:
python main.py
-
Local Testing (Optional):
# Test webhook locally python dev-tools/local_test.py test push # Or use PowerShell helper ./dev-tools/local-dev.ps1 test push
π Complete local testing guide: See docs/LOCAL_TESTING.md
Create a .env file with the following variables:
# Discord Bot Configuration
DISCORD_TOKEN=your_discord_bot_token_here
DISCORD_CHANNEL_ID=your_discord_channel_id_here
# GitHub Webhook Configuration
GITHUB_WEBHOOK_SECRET=your_github_webhook_secret_here
# Server Configuration (optional)
HOST=0.0.0.0
PORT=8000
DEBUG=False
LOG_LEVEL=INFO- π Railway (Recommended): Easy deployment with persistent connections
- β‘ Vercel: Free serverless option for internal use
- π³ Docker: Containerized deployment for any platform
- βοΈ Render: Alternative cloud platform
- Connect your repository:
- Go to Railway
- Connect your GitHub repository
Quick Setup:
- Click the "Deploy to Render" button above
- Set your environment variables during setup
- Wait for build completion (2-5 minutes)
- Configure GitHub webhook with your new Render URL
π Complete Render guide: See docs/RENDER_DEPLOYMENT.md
Fast deployment with excellent developer experience:
# One-click deploy
railway deploy --template=your-repo-
Connect your repository:
- Go to Railway
- Click "New Project" β "Deploy from GitHub repo"
- Select your repository
- Deploy automatically
-
Set environment variables in Railway dashboard:
DISCORD_TOKENDISCORD_CHANNEL_IDGITHUB_WEBHOOK_SECRET
-
Configure GitHub webhook:
- Use your Railway URL:
https://your-app.up.railway.app/webhook
- Use your Railway URL:
π Detailed Railway guide: See docs/RAILWAY_DEPLOYMENT.md
Perfect for internal use with serverless architecture:
# Quick deploy
npx vercel
# Set environment variables
vercel env add DISCORD_TOKEN
vercel env add DISCORD_CHANNEL_ID
vercel env add GITHUB_WEBHOOK_SECRETπ Detailed Vercel guide: See docs/VERCEL_DEPLOYMENT.md
For containerized deployment (Docker files are in root directory):
# Build and run with Docker Compose
docker-compose up --build
# Or build image manually
docker build -t patchy-discord-bot .
docker run -p 8000:8000 --env-file .env patchy-discord-botπ Complete Docker guide: See docs/DOCKER.md
- Railway will automatically detect the
railway.jsonconfiguration - Your bot will be deployed and running!
- Update GitHub webhook:
- Use your Railway domain:
https://your-app.railway.app/webhook
- Use your Railway domain:
-
Create a new Web Service:
- Go to Render
- Click "New" β "Web Service"
- Connect your GitHub repository
-
Configure the service:
- Build Command:
pip install -r requirements.txt - Start Command:
python main.py - Environment:
Python 3
- Build Command:
-
Set environment variables:
- Add all required environment variables
-
Deploy:
- Click "Create Web Service"
- Render will build and deploy your bot
-
Update GitHub webhook:
- Use your Render domain:
https://your-app.onrender.com/webhook
- Use your Render domain:
-
Build the image:
docker build -t github-discord-bot . -
Run the container:
docker run -d \ --name github-discord-bot \ -p 8000:8000 \ -e DISCORD_TOKEN=your_token \ -e DISCORD_CHANNEL_ID=your_channel_id \ -e GITHUB_WEBHOOK_SECRET=your_secret \ github-discord-bot
Your Discord bot needs the following permissions:
- Send Messages
- Embed Links
- Read Message History
- Use Slash Commands (if you plan to add them)
The bot supports these GitHub events:
push- New commitspull_request- PR eventsissues- Issue eventsrelease- Release eventscreate- Branch/tag creationdelete- Branch/tag deletion
You can customize the bot by modifying the embed creation functions in webhook_server.py:
- Change colors by modifying the
colorparameter - Add or remove fields in the embeds
- Modify the emoji and formatting
- Add custom logic for specific repositories
The bot provides health check endpoints:
GET /- Basic health checkGET /health- Detailed health information
The bot uses structured logging with different levels:
DEBUG- Detailed debugging informationINFO- General information about operationsWARNING- Warning messagesERROR- Error messages
The bot includes comprehensive error handling:
- Invalid webhook signatures are rejected
- Discord API errors are logged and handled gracefully
- Malformed GitHub payloads are handled safely
- Network issues are retried automatically
-
Bot not responding:
- Check if the bot is online in Discord
- Verify the Discord token is correct
- Check the channel ID is valid
-
Webhook not working:
- Verify the webhook URL is accessible
- Check the GitHub webhook secret matches
- Ensure the bot is running and healthy
-
Missing notifications:
- Check which events are selected in GitHub webhook settings
- Verify the bot has permission to send messages
- Check the logs for any errors
Enable debug mode for detailed logging:
DEBUG=True
LOG_LEVEL=DEBUGYou can test your webhook using curl:
curl -X POST https://your-domain.com/webhook \
-H "Content-Type: application/json" \
-H "X-GitHub-Event: push" \
-d '{"test": "payload"}'- Webhook Secret: Always use a strong, unique secret for GitHub webhooks
- Environment Variables: Never commit tokens or secrets to version control
- HTTPS: Always use HTTPS in production
- Permissions: Use the principle of least privilege for Discord bot permissions
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
If you encounter any issues:
- Check the troubleshooting section
- Review the logs for error messages
- Open an issue on GitHub with detailed information
- Initial release
- Support for push, pull request, issue, and release events
- Beautiful Discord embeds with rich formatting
- Comprehensive error handling and logging
- Ready for deployment on Railway, Render, and Docker