Skip to main content
Version: 1.x

File Naming Conventions

app.ts

The src/app.ts (or app.js) file is the entry point for your application. It should define and export your discord.js client instance.

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

const client = new Client({
/* options */
});

client.token = 'YOUR_BOT_TOKEN';

export default client;

Middleware Files

The src/app/commands tree supports three middleware filenames:

  • +global-middleware.ts: runs for every command
  • +middleware.ts: runs for leaves defined in the same directory
  • +<command>.middleware.ts: runs for the matching leaf token in the same directory
src/app/commands/+middleware.ts
import { MiddlewareContext } from 'commandkit';

export function beforeExecute(context: MiddlewareContext) {
console.log('Before command execution');
}

export function afterExecute(context: MiddlewareContext) {
console.log('After command execution');
}
info

You can learn more about middleware behavior here.

(category) Directory

Use parenthesis directories such as (Moderation) for organization only. Categories help structure the repo and category metadata, but they do not change slash command routes.

src/app/commands/
└── (Moderation)/
├── ban.ts
├── kick.ts
├── mute.ts
├── unmute.ts
├── warn.ts
├── warn-list.ts
└── warn-remove.ts
info

You can learn more about command categories here.

Hierarchical Command Directories

CommandKit uses distinct tokens for hierarchical command trees:

  • [command] for root command directories
  • {group} for subcommand group directories
  • command.ts for directory-backed command nodes
  • group.ts for group definition files
  • *.subcommand.ts for shorthand leaves
  • [leaf]/command.ts for directory-backed leaves
src/app/commands/
└── [settings]/
├── command.ts
├── profile.subcommand.ts
└── {notifications}/
├── group.ts
├── enable.subcommand.ts
└── [disable]/
└── command.ts

This transforms into:

  • /settings profile
  • /settings notifications enable
  • /settings notifications disable

Middleware inside these trees follows the same same-directory rule:

  • +middleware.ts applies only to leaves defined in that directory
  • +<command>.middleware.ts applies only to the matching leaf token in that directory
  • ancestor directories do not automatically contribute middleware to deeper hierarchical leaves
info

You can learn more about configuring tree structures here.