Setup CommandKit
You can quickly setup a new CommandKit project using create-commandkit
— a command-line utility used for creating new discord.js applications with CommandKit. To get started, run the following command:
- npm
- Yarn
- pnpm
npx create-commandkit@latest
yarn dlx create-commandkit@latest
pnpm dlx create-commandkit@latest
This will start the CLI in the current directory which will help you quickly setup a base CommandKit project.
Project structure
By using the CLI to create a base project, you should get a project structure that looks like this:
.
├── src/
│ ├── app/
│ │ ├── commands/
│ │ │ └── ping.ts
│ │ └── events/
│ │ └── ready/
│ │ └── log.ts
│ └── app.ts
├── .env
├── .gitignore
├── commandkit.config.ts
├── package.json
└── tsconfig.json
The src/app.ts
file is the main entry point for your application. This file default exports the discord.js client which commandkit loads at runtime. For example, the src/app.ts
file looks like this:
import { Client } from 'discord.js';
const client = new Client({
intents: [
/* add stuff */
],
});
// setting up the token manually
client.token = process.env.MY_BOT_TOKEN;
export default client;
Notice how we are not calling client.login()
in this file. This is because commandkit will automatically call client.login()
for you when the application starts.
Also, you might have noticed that we are not using anything from commandkit in this file. This is because commandkit is designed to reduce boilerplate code and make it easier to build discord bot applications.
The src/app
directory is a special directory that commandkit understands. All the commands and events in this directory will be automatically registered when the application starts.
Development version
The development version is likely to have bugs.
If you'd like to try the latest development builds, you can use the @dev
tag like so:
- npm
- Yarn
- pnpm
npx create-commandkit@dev
yarn dlx create-commandkit@dev
pnpm dlx create-commandkit@dev