Skip to main content

File Naming Conventions

app.ts

The src/app.ts (or app.js) is a special file that acts as the entry point for your application. It is where you define and export your Discord.js client instance.

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

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

// Optional: Override the default DISCORD_TOKEN environment variable
client.token = 'YOUR_BOT_TOKEN';

export default client;

+middleware.ts

The src/app/commands/+middleware.ts (or +middleware.js) file is used to define middleware functions for your application. Middleware functions get called before and after the command execution.

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

export function beforeExecute(context: MiddlewareContext) {
// This function will be executed before the command is executed
console.log('Before command execution');
}

export function afterExecute(context: MiddlewareContext) {
// This function will be executed after the command is executed
console.log('After command execution');
}

There are 3 types of middlewares you can create:

  • +middleware.ts (or +middleware.js): This file is used to define middleware functions that will be executed for all sibling commands in the application.
  • +<command>.middleware.ts (or +<command>.middleware.js): This file is used to define middleware functions that will be executed for a specific command in the application. The <command> part of the filename should match the name of the command file. This is useful for defining middleware functions that should be applied to a specific command.
  • +global-middleware.ts (or +global-middleware.js): This file is used to define middleware functions that will be executed for all commands in the application, regardless of their location in the file system.
info

You can learn more about middlewares here.

(category) directory

In your commands directory, you can create a category using parenthesis (e.g. (Moderation)). This is useful for organizing your commands into logical groups, making it easier to manage and maintain your code.

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.