- Create an application on the Discord Developer Portal
- Add a "Bot" to the application and copy its token (required for
BOT_TOKEN) - Enable all "Privileged Gateway Intents"
- Copy the "Client ID" from the "OAuth2" page (required for
BOT_CLIENT_ID) - Go to the "Installation" page
- Under "Installation Contexts" select "Guild Install"
- Under "Install Link" select "Discord Provided Link"
- Under "Default Install Settings" select
applications.commandsandbotscopes withAdministratorpermissions - The generated link under "Install Link" should allow you to invite the bot to your server
- Invite the bot to a server you will be using for development
- Take note of the server ID (required for
BOT_DEVELOPER_GUILD_IDS)
The apps/bot/seed.ts file contains basic data that is loaded into the database by bun seed. It sources some default settings from apps/bot/src/specializedConstants.ts.
bun reload-commands needs to be ran every time a change is made to command signatures, e.g. changing a name, parameter, creating a new command or deleting a command. The reload-commands script syncs commands to guilds set in BOT_DEVELOPER_GUILD_IDS. This step can be skipped if only command handlers are changed or any other code that wouldn't change a command's signature.
Using VSCode Dev containers is the easiest way to setup the development environment with required tools and services. You need the Dev Containers extension and Docker to start using them.
-
Copy
.env.exampleto.envand set the following variables:BOT_TOKENBOT_CLIENT_IDBOT_DEVELOPER_GUILD_IDS- Don't change
REDIS_URL,DATABASE_*andPOSTGRES_*- they are setup to work out of the box in Dev Containers - Optionally set vars from the "Optional settings" section if needed
-
Run "Dev Containers: Reopen in Container". VSCode should build an image with Docker and start required services (Postgres, Redis).
-
Dependencies should be installed automatically on container creation, but you can install them manually with
bun install -
Setup the database:
bun prisma-generate- generate the Prisma DB clientbun prisma-migrate-deploy- sync the schemabun seed- insert required data
-
Sync commands to discord -
bun reload-commands -
Start the bot -
bun start
-
Copy
.env.exampleto.envand set the following variables:BOT_TOKENBOT_CLIENT_IDBOT_DEVELOPER_GUILD_IDSREDIS_URL=redis://localhost:6379DATABASE_URL=postgresql://username@localhost:5432/devDATABASE_TEST_URL=postgresql://username@localhost:5432/testPOSTGRES_*vars can be removed - they are only used when initializing a DB via Docker- Optionally set vars from the "Optional settings" section if needed
-
Activate the devShell
- Use
direnv allowto automatically go into a devShell and load the.envfile, or - Activate the shell manually with
nix developand load the.envfile manually (e.g. by sourcing it)
- Use
-
Install dependencies -
bun install -
Start development databases -
start-database && start-redis -
Setup the database:
bun prisma-generate- generate the Prisma DB clientbun prisma-migrate-deploy- sync the schemabun seed- insert required data
-
Sync commands to discord -
bun reload-commands -
Start the bot -
bun start -
When you're finished, stop development databases -
stop-database && stop-redis
Use the helper script in scripts/bunVersion.ts anytime you need to bump the Bun runtime. It updates the devcontainer image, production Dockerfile, CI workflow, Nix shell, and the @types/bun dev dependency so everything stays in sync.
# To preview changes without writing them:
bun bump 1.4.0 --dry-run
# To execute the changes
bun bump 1.4.0
# Afterwards refresh dependencies to update bun.lock
bun install