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.
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
import { MiddlewareContext } from 'commandkit';
export function beforeExecute(context: MiddlewareContext) {
console.log('Before command execution');
}
export function afterExecute(context: MiddlewareContext) {
console.log('After command execution');
}
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
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 directoriescommand.tsfor directory-backed command nodesgroup.tsfor group definition files*.subcommand.tsfor shorthand leaves[leaf]/command.tsfor 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.tsapplies only to leaves defined in that directory+<command>.middleware.tsapplies only to the matching leaf token in that directory- ancestor directories do not automatically contribute middleware to deeper hierarchical leaves
You can learn more about configuring tree structures here.