Skip to main content
Version: Next

Using CommandKit CLI

CommandKit CLI is a powerful tool that streamlines the development and deployment of your Discord bot application. It provides essential features like Hot Module Replacement (HMR), automatic crash recovery, and TypeScript support out of the box.

Getting Started

To view all available CLI commands, run the following in your project directory:

npx commandkit --help

You'll see a list of available commands and options:

Usage: commandkit [options] [command]

Options:
-h, --help display help for command

Commands:
dev [options] Start your bot in development mode.
start [options] Start your bot in production mode after running the build command.
build [options] Build your project for production usage.
create [options] <name> Create new commands, events, or locale files
help [command] display help for command

Core Commands

Development Mode (commandkit dev)

The development mode is optimized for local development with features like:

  • Hot Module Replacement (HMR): Automatically reloads your bot when you make changes to commands or events
  • TypeScript Support: Built-in TypeScript compilation and type checking
  • Environment Variables: Automatic loading of .env files
  • Error Handling: Detailed error messages and stack traces

Example usage:

# Start development server
npx commandkit dev

Production Build (commandkit build)

Creates an optimized production build of your bot application with:

  • TypeScript Compilation: Converts TypeScript to JavaScript
  • Type Checking: Validates your code for type errors
  • Code Optimization: Minifies and optimizes your code
  • Output Directory: Builds to dist/ by default

Configuration options in commandkit.config.ts:

import { defineConfig } from 'commandkit';

export default defineConfig({
typescript: {
ignoreBuildErrors: true, // skip type checking
},
});

Production Mode (commandkit start)

Runs your bot in production mode. Always run commandkit build first.

# Build and start in production
npx commandkit build
npx commandkit start

File Generation (commandkit create)

Quickly scaffold new files in your project:

# Create a new command
npx commandkit create command ping

# Create a new event
npx commandkit create event ready

Best Practices

  1. Development Workflow:

    • Use commandkit dev during development for instant feedback
    • Enable debug mode when troubleshooting issues
    • Keep your .env file updated with all required variables
  2. Production Deployment:

    • Always run commandkit build before deploying
    • Test the production build locally before deployment
    • Use environment variables for sensitive data
  3. TypeScript Usage:

    • Enable strict type checking in development
    • Use type annotations for better code quality
    • Consider using ignoreBuildErrors only in specific cases

Troubleshooting

Common issues and solutions:

  • Build Errors: Check TypeScript configuration and type definitions
  • Environment Variables: Ensure .env file exists and contains required variables
  • Hot Reload Issues: Verify file paths and module exports. Hot reload only works for commands, events and the paths supported by the active plugins. Changes made to other paths will trigger full reload.

For more detailed information about specific commands and options, use:

npx commandkit help <command>