Runtime Flow
Bight’s runtime has two phases: startup and execution. Both follow a fixed sequence, which makes features like preconditions, cooldowns, and maintenance mode behave predictably.
Startup
Section titled “Startup”When you run pnpm start:with-deploy or pnpm dev, Bight processes these steps in order before connecting to Discord:
-
Instantiation
Creates the logger and builds services defined in
src/bight.ts. -
Discovery
Scans
src/commands/,src/interactions/,src/events/, andsrc/preconditions/for handler files. -
Feature merging
If feature modules are defined, their commands and handlers merge into the routing table.
-
Plugin setup
Registered plugins run their
setuphooks. Plugins can add commands, preconditions, and event listeners at this stage. -
Router attachment
Binds the interaction and event routers to the Discord client.
-
Login
Establishes the WebSocket connection with Discord.
Execution
Section titled “Execution”When a user triggers a slash command, clicks a button, or submits a modal:
-
Routing
Bight matches the incoming Discord payload to the correct handler file.
-
Global preconditions
Evaluates preconditions registered globally (e.g, maintenance mode).
-
Local preconditions
Evaluates preconditions attached to the specific command or handler.
-
Environment check
If the command is marked
devOnly, blocks execution in production. -
Cooldown enforcement
Checks and enforces any configured rate limits.
-
Execution
Runs your
execute()handler. -
Diagnostics
Records the result (success, error, or denial) in the diagnostics hub.
If a precondition fails at step 2 or 3, the handler at step 6 is never reached. The diagnostics hub still records the denial, so you can inspect what happened through the devtools plugin.