Skip to main content

Discord Bot

Scaffold a Discord bot with discord.js, TypeScript, and explicit development and production entry points.

Why Use This Command?

  1. Separates Discord client construction from login so Vitest can exercise the starter without connecting to Discord.
  2. Keeps the bot token in an untracked .env file while documenting the required key in the tracked .env.sample.
  3. Uses a fixed-width Nova header and clear connection states while keeping the bot token out of terminal output.
  4. Uses Nova's type-check and transpile utilities so checking and production output follow the same contract as other workspaces.
  5. Can contribute the background service to the repository-wide s6 Docker appliance without adding an HTTP port.

Requirements

  • Node.js runtime — Use any Node.js LTS release.
  • Discord application token — Create a bot in the Discord Developer Portal, add it to a server with the bot scope, and provide its token as DISCORD_TOKEN after scaffolding.
  • Empty directory or monorepo root — Nova auto-detects whether to create a project or add a workspace.

Usage

Options

FlagDescription
-d, --dry-runRun without writing any files.
--docker-imageAdd the bot as a supervised service in the repository-wide s6 image.
--installInstall dependencies after scaffolding; this is the default.
--no-installSkip dependency installation.
--name <name>Project slug when creating a new monorepo; omit at an existing root.
--non-interactiveRequire every answer as a flag and do not open prompts.
--workspace-name <name>Workspace directory name.
--output <dir>Output directory.

Output Files

FileDescription
.envUntracked Nova defaults and the blank DISCORD_TOKEN value.
.env.sampleShareable Nova defaults and the required DISCORD_TOKEN key.
src/bot.tsImport-safe client factory, login flow, and status output.
src/bot.test.tsOffline Vitest coverage for intents, status, and validation.
src/index.tsRuntime token lookup and bot startup.
tsconfig.*.jsonNova strict Node.js configs for source, tooling, and tests.
package.jsondiscord.js dependencies and Nova-managed workspace scripts.

With --docker-image, Nova adds root .dockerignore, Dockerfile, and compose.yml entry points plus private assembly files under packages/docker. The bot runs as a supervised longrun inside the repository's one s6 image.

See Docker Images for the shared runtime and layout contract.

First Run

  1. Create a Discord application and bot in the Discord Developer Portal.
  2. Open the application's Installation page and add the bot to your server with the bot scope. Installing only the application-command integration does not add a visible bot member.
  3. Set DISCORD_TOKEN in the generated .env, then run the workspace dev command shown by Nova.

Nova doesn't request or store the token during scaffolding, and the token should not be passed as a command-line flag. The root .gitignore generated by every Nova scaffold excludes .env files while keeping .env.sample tracked.

When the token is missing, the generated bot prints these setup steps instead of a stack trace.

Non-Interactive Mode

bash
nova scaffold app discord-bot --non-interactive --name my-bot --workspace-name bot --output ./my-bot
nova scaffold app discord-bot --non-interactive --workspace-name bot --output ./apps/bot
nova scaffold app discord-bot --docker-image --non-interactive --name my-bot --workspace-name bot --output ./my-bot

Registration

Nova registers the workspace with the app role and trackable policy. Its package name follows {projectSlug}-app-{workspaceName}.

Nova also registers a same-named file artifact containing the runtime package.json and compiled build/ tree. Docker publishing remains a separate repository-wide OCI artifact.