Skip to main content
Version: Next

Migrating from CommandKit v0

This comprehensive guide will walk you through migrating your Discord bot from CommandKit v0 to v1. CommandKit v1 introduces significant architectural improvements, including a framework-based approach with enhanced developer experience features.

info

This guide uses TypeScript examples, but all concepts apply to JavaScript projects as well. Simply use the corresponding JavaScript file extensions (e.g., app.js, commandkit.config.js).

warning

Minimum Requirements: CommandKit v1 requires Node.js version 22 or higher. Please ensure your environment meets this requirement before proceeding.

warning

Migration Focus: This guide specifically covers converting existing v0 code to v1. For information about new v1 features and capabilities, please refer to the rest of the documentation after completing your migration.

Updating CommandKit

Begin your migration by updating to the latest version of CommandKit:

npm install commandkit@dev

This command will install CommandKit v1 and update your package.json with the latest version.

Project Structure Migration

CommandKit v1 adopts a framework-based approach with a structured app directory that serves as the primary location for your bot's functionality. This new structure provides better organization and enables advanced features like automatic route discovery.

.
├── src/
│ ├── app/
│ │ ├── commands/
│ │ │ └── ping.ts
│ │ └── events/
│ │ └── ready/
│ │ └── log.ts
│ └── app.ts
├── .env
├── commandkit.config.ts
├── package.json
└── tsconfig.json

Configuration File Updates

CommandKit v1 significantly simplifies configuration by automatically detecting your project structure and entry points. The framework now supports a standardized set of configuration file names for consistency.

Supported Configuration Files:

  • commandkit.config.js
  • commandkit.config.mjs
  • commandkit.config.cjs
  • commandkit.config.ts
commandkit.config.ts
import { defineConfig } from 'commandkit';

export default defineConfig({
// Configuration is now optional for most use cases
// CommandKit automatically detects your app structure
});
info

The CommandKit CLI commands (commandkit dev, commandkit build, commandkit start) continue to work seamlessly with the new configuration system.

Entry Point Transformation

CommandKit v1 introduces a dramatically simplified entry point system. Instead of manually managing the CommandKit instance, bot login, and path configurations, you now simply export a configured Discord.js client.

src/app.ts
import { Client } from 'discord.js';

const client = new Client({
intents: [
'Guilds',
'GuildMessages',
'MessageContent',
],
});

// Optional: Override the default token environment variable
client.token = process.env.CUSTOM_TOKEN_VAR;

export default client; // CommandKit handles the rest automatically

Command File Structure

CommandKit v1 modernizes the command API with more intuitive naming and cleaner type definitions. The new structure separates command metadata from execution logic more clearly, while introducing room for new APIs such as message (legacy) commands.

src/app/commands/ping.ts
import type { CommandData, ChatInputCommandContext } from 'commandkit';

export const command: CommandData = {
name: 'ping',
description: 'Pong!',
};

export function chatInput({ interaction }: ChatInputCommandContext) {
interaction.reply('Pong!');
}

Middleware System (Formerly Validations)

CommandKit v1 renames and enhances the validation system to "middleware," which better reflects its purpose and capabilities. Middleware can now run in various contexts and provides more granular control over command execution.

src/app/commands/+global-middleware.ts
import type { MiddlewareContext } from 'commandkit';

export function beforeExecute(ctx: MiddlewareContext) {
// Example: Block command execution based on conditions
if (ctx.interaction.isRepliable()) {
ctx.interaction.reply('Access denied: Command execution blocked.');
}

ctx.cancel(); // Prevents command execution
}

For comprehensive middleware documentation, including command-specific and conditional middleware, refer to the middleware documentation.

Development Environment

CommandKit v1 introduces advanced development features that require using the CommandKit CLI. The development server provides Hot Module Replacement (HMR) for rapid iteration and supports modern features like JSX components.

Starting Development Server

npx commandkit dev
warning

Generated Files: The development server creates a .commandkit directory for temporary files. Add this to your .gitignore to prevent committing generated files:

.commandkit/

Production Deployment

Building Your Application

npx commandkit build

Starting Production Application

Option 1 - Using CommandKit CLI (Recommended):

npx commandkit start

Option 2 - Direct Node.js execution:

node dist/index.js
warning

Generated Build Files: The build process creates a dist directory. Add this to your .gitignore to prevent committing build artifacts:

dist/