GitHub Discord Bot
Manage GitHub issues and get activity reports from Discord.
/addcreate an issue, in one line or a form/listopen issues, with a menu to close one/doneclose an issue/todayissues created today/staleopen issues older than 14 days/reposregistered repositories/registerregister one repository/sync-reposregister every repository you own/repo-infolanguage, stars, forks, last push/statscommits & issues by period/streakcommit streak/top-repomost active repo this month/helpevery command, grouped
What it does
GitHub Discord Bot brings my GitHub account into a Discord server. I built it for the Human–Computer Interaction course, so the interaction design mattered as much as the integration: autocomplete wherever a value can be guessed, buttons and menus instead of typed numbers, a form when there is more to say, and one card style whose colours carry meaning.
/add opens a GitHub issue in one line, or through a form with a description field when there is no title. Words such as crash, ne radi, add or readme in the title add the bug, enhancement or documentation label. Every new issue comes back as a card with a link to GitHub and a Close button, and /list shows the open issues across all repositories, with a menu to close any of them and pages instead of a cut-off list.
For activity, /stats counts commits and issues per repository for the last 7 days, this month or last month, /streak works out the current commit streak and the longest one in the last 90 days, and /top-repo names the most active repository of the month. The bot also posts on its own: a monthly report on the 1st and a reminder of stale issues every Monday, both at 09:00 in my time zone.
It works the other way round too. Issues opened or closed on GitHub, pull requests opened or merged, failed CI runs and published releases appear in a Discord channel through a signed webhook, while changes made from Discord are not announced a second time. Only the owner can use any of it, even if others on the server see the commands.
Architecture
One Python process runs two things: the Discord bot on the asyncio event loop, and a small Flask server on its own thread for GitHub’s webhook and the health check.
- The Cogs hold the slash commands, one module per area: issues, repositories, stats with the monthly report, activity, and reminders with the weekly task. Every command, autocomplete, button and menu passes the same owner check first.
- The views are the buttons, menus, pagers and the issue form. Their state lives in their
custom_id, so the Close button and the/listcontrols still work on old messages after a restart. - Issue actions open and close issues for the commands, the buttons and the form alike: GitHub first, then the database.
- The webhook thread verifies each delivery, saves issue changes to the database, and hands the card to the bot’s event loop to post.
core/holds the pure logic (labels, periods, paging, streaks, reports and access), andui/embeds.pyevery card the bot sends, with Discord’s limits in one place.- Supabase keeps the registered repositories and the issues, one row per repository and issue number.
The GitHub and Supabase clients are synchronous, so every call goes through asyncio.to_thread and the bot keeps answering Discord while it waits.
Decisions and why
- Owner only, checked once. Strangers get a private “not for you” card, and their autocomplete shows nothing.
- One server, no global commands. The commands are synced to the configured server only, so a change shows up at once and nothing is listed twice.
- GitHub first, database second. An issue is marked closed in the database only after GitHub accepted it, so a failure never leaves the two disagreeing.
- One card per action. Before the bot changes something on GitHub it remembers the change for five minutes, so the webhook GitHub sends back updates the database but posts nothing.
- A form only when it helps.
/addwith a title is one line; without one it opens a form, because a description doesn’t fit in a slash option. - My clock, not the server’s. “Today”, the streaks and the scheduled messages follow the configured time zone, daylight saving included; GitHub always gets UTC.
- Fewer requests. Repositories whose last push is older than the requested period are skipped, the rest are fetched in parallel, and repository names for autocomplete are cached for a minute.
- One unreadable repository doesn’t sink a report. If the token may not read a repository’s commits (
403),/stats,/streakand/top-repoleave it out and log a warning instead of failing.
Security
- The webhook is signed. Each delivery is checked against
X-Hub-Signature-256with HMAC-SHA256, compared in constant time, and a bad signature gets401. - Owner only. Nobody else on the server can create, close or browse issues, whatever they can see.
- No privileged intents. The bot uses only slash commands and components, so it never asks to read message content.
- A least-privilege token. The bot runs with a fine-grained GitHub token with an expiry date: read-only metadata and contents, and read and write issues.
- Settings are checked at start-up. The bot reads every setting from the environment and lists all the missing or invalid ones in one error instead of starting half-configured.
Testing and deployment
There are 237 tests with pytest, pytest-asyncio and responses, at 99% coverage. They run in a few seconds with no network: the GitHub API is mocked, the commands run as async tests, and the pure logic in core/ is tested with plain values. GitHub Actions runs Ruff and the tests on every push to master, but not when only the README, the demo GIF or other documentation changed, and a newer push cancels the run still in progress.
The bot runs as one web service on Render, from a Blueprint. Render deploys only after CI passes and ignores commits that only touch tests, workflows or documentation, so a README edit never restarts the bot. A free Render service sleeps after 15 minutes without HTTP traffic, which would also disconnect the bot, so UptimeRobot calls /health every five minutes. A daily task also reads one row from Supabase, so the free database is never paused for inactivity.