Skip to main content
Guide for developers contributing to the Doubt Discord Bot.

Development Setup

See Getting Started for full setup instructions. Quick start:

Project Scripts

Code Structure

Adding a Slash Command

Create a new file in src/commands/slash/<Category>/:
The command is automatically loaded at startup and registered on DEV_GUILD_ID.

Adding a Developer Command

Create a new file in src/commands/devOnly/Developers/:

Adding a Prefix Command

Create a new file in src/commands/prefix/<Category>/:
Remember: prefix commands are disabled by default (config.handler.commands.prefix).

Adding a Component Handler

Button

Create in src/components/buttons/:

Select Menu

Create in src/components/selects/:
Create in src/components/modals/:

Adding a Context Menu

Create in src/contextmenus/:

Adding a Database Model

  1. Add the model to prisma/schema.prisma
  2. Run npx prisma generate to regenerate the client
  3. Create a schema re-export in src/schemas/:
  1. Import and use in your command:

Testing

Running Tests

Tests use Node.js built-in test runner (node:test) and do not require MongoDB, Discord, or any external service.

Writing Tests

Create test files in tests/ with the .test.js extension:

Test Philosophy

  • Tests should be pure unit tests that can run without external services
  • Focus on business logic, not Discord API interactions
  • Test edge cases for economy calculations, permission checks, and data validation
  • Use node --check for syntax verification of command files

Existing Test Coverage

Code Conventions

Command Handler Signature

All slash and developer commands use:
Prefix commands use:

Database Access

Always use the Prisma model delegates via schema re-exports:

Error Handling

  • Use try/catch around database operations and Discord API calls
  • Log errors with log(error, "err") from src/functions
  • For interaction handlers, always ensure a reply is sent (even on error)
  • Use ephemeral: true for error messages

Logging

Use the log function from src/functions:

Pull Request Guidelines

  1. Run npm test before opening a PR — all tests must pass
  2. Run node --check on any modified command files to verify syntax
  3. Add regression tests for bug fixes when practical
  4. Keep commits focused and descriptive
  5. Update documentation if adding new features or changing behavior