Astro
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:
Resources:
Table of Contents
About The Project
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!
I do not provide support for self-hosting the bot.
AI Usage
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.
Development
Prerequisites
- JDK 25
- Docker
- just
- Infisical CLI, secrets and configs are there, there are no
.env files to fill by hand
- IntelliJ (not necessary but recommended)
Understanding the codebase
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:
bot
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 user
InteractionHandlers: 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 categories
guards: 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
api-central
A REST api for the bot, it’s used by the dashboard to retrieve settings and data from the bot database.
Users log in with Discord OAuth and get a session cookie, MCP clients use OAuth access tokens issued by api-central itself, docs/authentication.md explains how.
entitlements-expiration-job
Simple service that checks for expired Discord premium application entitlements and updates the bot database.
Nothing fancy, ran as a k8s cronjob.
support-bot
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
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 by DAY on the timestamp field.
The schemas are in infra/terraform/gcp/main.tf, which can also create everything for you.
Example queries are in docs/analytics/queries.
- Create a service account with the
BigQuery Admin permission (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.
Running the application
- Run Docker compose
just docker-up
- Run the services,
just pulls the configs from the dev environment of Infisical (each variable of application.yml is there)just run-bot
just run-api-central
just run-support-bot
just run-entitlements-expiration-job
If using IntelliJ you can also run them from the IDE, using just generate-env to export the variables to a .env file.
- 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.
MongoDB and Redis dashboards
You can use some web dashboards for local dev with MongoDB and Redis:
Editing documents with the MongoDB dashboard is not recommended as it tends to mess up data types!
OpenAPI
You can access the OpenAPI documentation for each service at the following URLs:
(back to top)
Deployment
I do not provide support for self-hosting the bot.
Prerequisites
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_ORGANIZATION variable in .semaphore/semaphore.yml to your GitHub username or organization name.
- Go into Organization settings > Secrets and add the following secrets:
-
github with these environment variables:
| Environment Variable |
Description |
| GITHUB_ACTOR |
GitHub username for actions |
| GITHUB_TOKEN |
GitHub token for authentication, instructions |
-
sentry with these environment variables:
| Environment Variable |
Description |
| SENTRY_AUTH_TOKEN |
Sentry auth token, instructions |
-
infra-deploy-key with the following configuration files:
| Configuration Files |
Description |
/home/semaphore/.ssh/infra_deploy_key |
Private key of a deploy key with write access to your infra fork |
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
infra via a promotion button for production, then ArgoCD deploys it (the automatic staging deploy is currently disabled, see the commented promotions in .semaphore/semaphore.yml)
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.
(back to top)
Contributing
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
(back to top)
Top contributors:
License
Distributed under the AGPL-3.0 license. See LICENSE.txt for more information.
(back to top)
(back to top)
评论