Astro is the most unique and complete discord bot for temporary voice channels and voice roles!
This repository contains the code for the backend of the bot.
Other repositories:
- Frontend
- Infrastructure (GitOps) and cluster (Terraform)
Resources:
I initially built this bot for my friends Discord, but then it grew way beyond my expectations.
You can read the story of this project on my blog post!
Warning
I do not provide support for self-hosting the bot.
This project was born and lived long of its life in the pre-AI-era.
In November 2026 I used AI for the first time to write code for Astro.
I froze all the code that was written before that in pre-ai-era branches in both Backend and Frontend repositories, so if you are interested in some human artifacts built by pulling all nighters to fix bugs and kubernetes deployments, those branches will serve you well.
- JDK 25
- Docker
- just
- Infisical CLI, secrets and configs are there, there are no
.envfiles to fill by hand - IntelliJ (not necessary but recommended)
Everything runs via SpringBoot and there is a shared/core module that contains the shared code between the services.
Code is mostly well documented / self-explanatory, so you should be able to take a look at it and get an idea of how things work quite easily.
This project contains four services:
The Discord bot itself, it receives events from Discord and responds to them.
All events are bridged from JDA (the Java library to interact with the Discord API) to SpringBoot.
Regarding interactions, like slash commands, buttons, menus and modal, their logic is almost all unified in the interactions package:
InteractionResponder: used by all interactions to submit replies to the userInteractionHandlers: the type-independent interaction declarations, their implementation can be a command, button, menu, etc...InteractionContext: groups together everything needed by any type of interaction to run, has subclasses for interaction categoriesguards: checks that run before an interaction (permissions, premium, votes)
Messages are built with Components V2, using the blocks in ui/Containers.kt, and texts live in shared/core/src/main/resources/i18n (managed on Crowdin).
It includes a small REST api for retrieving roles and channels that the dashboard needs to present the user with.
The dashboard doesn't directly query the bot service, but instead queries api-central which in turn queries the bot service.
It interacts with:
- BigQuery: for storing statistics about the bot usage
- MongoDB: storage for user / guild settings
- Redis: volatile cache and storage for temporary voice channels data
A REST api for the bot, it's used by the dashboard to retrieve settings and data from the bot database.
User authentication is managed via a combination of JWT tokens and session cookies, docs/authentication.md explains how.
Simple service that checks for expired Discord premium application entitlements and updates the bot database.
Nothing fancy, ran as a k8s cronjob.
A Discord bot that manages the support server of the bot, mainly used to apply the premium role to premium users.
Includes a REST api used by the bot service, when it receives an entitlement event from Discord, it sends a request to the support bot to update the user's role.
BigQuery is used for gathering statistics about the bot usage, mainly commands used, guilds joined / left, temporary voice channels generated, configuration errors and a daily snapshot of each guild configuration.
It is completely optional and you can skip configuring it if you don't need it (BOT__BIGQUERY_ENABLED=false). api-central writes the install source of each invite to INSTALL_EVENT and has its own CA__BIGQUERY_ENABLED and CA__BIGQUERY_DATASET_NAME.
If you instead want to use it, you need to:
- Create an account and a project on Google Cloud
- Enable BigQuery API
- Create a dataset
- Create the 7 tables (
CONFIGURATION_ERROR,CONNECTION_INVOCATION,GUILD_CONFIG_SNAPSHOT,GUILD_EVENT,INSTALL_EVENT,SLASH_COMMAND_INVOCATION,TEMPORARY_VC_GENERATION), all partitioned byDAYon thetimestampfield.
The schemas are ininfra/terraform/gcp/main.tf, which can also create everything for you.
Example queries are indocs/analytics/queries. - Create a service account with the
BigQuery Adminpermission (well that's a bit overkill so you can select the appropriate permissions if you need). - Create and download a JSON key, you will be asked for its content in the config.
To configure authentication to BigQuery for local development, instead of using the JSON key, you can follow these instructions.
While for production, you should use the JSON key.
- Run Docker compose
just docker-up
- Run the services,
justpulls the configs from thedevenvironment of Infisical (each variable ofapplication.ymlis there)If using IntelliJ you can also run them from the IDE, usingjust run-bot just run-api-central just run-support-bot just run-entitlements-expiration-job
just generate-envto export the variables to a.envfile. - If you forked the repo, set
GHCR_ORGANIZATION(see Configure Semaphore) to your GitHub username or organization name.
All the services should be up and running at this point.
Run just to see all the other tasks, and just hooks before committing.
You can use some web dashboards for local dev with MongoDB and Redis:
| Service | web dashboard |
|---|---|
| MongoDB | localhost:8081 |
| Redis | localhost:8082 |
Caution
Editing documents with the MongoDB dashboard is not recommended as it tends to mess up data types!
You can access the OpenAPI documentation for each service at the following URLs:
| Service | development url |
|---|---|
| bot | localhost:9000/docs |
| api-central | localhost:9001/docs |
| support-bot | localhost:9002/docs |
Warning
I do not provide support for self-hosting the bot.
- A fork of this repository
- Kubernetes cluster with ArgoCD, Infisical operator and sealed-secrets
- A fork of the infra repository, that is what ArgoCD deploys
- Redis instance
- MongoDB instance
- Infisical project
- Semaphore account
- Sentry
All the configs and secrets of the services live in Infisical, the Infisical operator syncs them in the cluster, check the application.yml of each service to see what they need.
How to set up the cluster and deploy with ArgoCD is explained in the infra repository.
- Create a new organization
- Fork this repository
- Create a new project in the newly created organization, using your forked repository
- Update the
GHCR_ORGANIZATIONvariable in.semaphore/semaphore.ymlto your GitHub username or organization name. - Go into Organization settings > Secrets and add the following secrets:
-
githubwith these environment variables:Environment Variable Description GITHUB_ACTOR GitHub username for actions GITHUB_TOKEN GitHub token for authentication, instructions -
sentrywith these environment variables:Environment Variable Description SENTRY_AUTH_TOKEN Sentry auth token, instructions -
infra-deploy-keywith the following configuration files:Configuration Files Description /home/semaphore/.ssh/infra_deploy_keyPrivate key of a deploy key with write access to your infrafork
-
Now when you commit to master, Semaphore will automatically:
- build the Docker image for each service that changed
- upload it to GitHub Container Registry
- update the version in
infravia a promotion button for production, then ArgoCD deploys it (the automatic staging deploy is currently disabled, see the commented promotions in.semaphore/semaphore.yml)
Note
Images are tagged with the commit sha and are only built for the services that changed in that commit, so promote a service to production from a build that actually included it.
If you have an idea, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Distributed under the AGPL-3.0 license. See LICENSE.txt for more information.
