Skip to main content
The bot automatically ensures that everyone who runs a command has a row in the database. No separate sign-up step — registration happens transparently before the command handler runs.

How it works

  1. Event handler integration — user management runs from the main event handlers in src/events/common.ts.
  2. Automatic check — every slash command (and prefix command) checks whether the caller exists in the database.
  3. Automatic creation — if not, a new User row is created.
  4. Username updates — if the row exists but the Discord username changed, it is updated.

Database model

The internal User.id UUID is what foreign keys use — not the Discord snowflake.

Key functions

ensureUserExists(discordId, username)

  • Looks up by Discord id.
  • Creates a row when missing.
  • Updates username when it changed.
  • Returns the database user object.

getUserByDiscordId(discordId)

Retrieves a user by Discord id without creating one.

Event integration

Slash commands call ensureUserExists before dispatch:
Prefix commands do the same for message.author.

Error handling

Database errors are logged. If user creation fails, the existing error handler surfaces it to the caller. Production (main.ts) closes the Prisma connection on SIGINT/SIGTERM; development (dev.ts) does not.

Using it in commands

Any command can assume the caller has a User row after the event hook runs:
/profile uses the same helper instead of duplicating create/update logic.