Skip to content

Commit a8f934b

Browse files
committed
add guide to website
1 parent 5cead41 commit a8f934b

13 files changed

+1440
-20
lines changed

apps/website/docs/api-reference/intro.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
sidebar_position: 1
33
---
44

5-
# API reference intro
5+
# API reference
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
---
2+
title: Installation
3+
description: Learn how to install CommandKit.
4+
---
5+
6+
import Tabs from '@theme/Tabs';
7+
import TabItem from '@theme/TabItem';
8+
9+
# Installation
10+
11+
<div align="center" className="my-8">
12+
<img src="/img/ckit_logo.svg" width="60%" />
13+
<br />
14+
<div className="flex items-center justify-center gap-2">
15+
<a href="https://ctrl.lol/discord">
16+
<img
17+
src="https://img.shields.io/discord/1055188344188973066?color=5865F2&logo=discord&logoColor=white"
18+
alt="support server"
19+
/>
20+
</a>
21+
<a href="https://www.npmjs.com/package/commandkit">
22+
<img
23+
src="https://img.shields.io/npm/v/commandkit?maxAge=3600"
24+
alt="npm version"
25+
/>
26+
</a>
27+
<a href="https://www.npmjs.com/package/commandkit">
28+
<img
29+
src="https://img.shields.io/npm/dt/commandkit?maxAge=3600"
30+
alt="npm downloads"
31+
/>
32+
</a>
33+
</div>
34+
</div>
35+
36+
To install CommandKit, run one of the following commands based on your preferred package manager:
37+
38+
<Tabs>
39+
<TabItem value='npm' label='npm'>
40+
```
41+
npm install commandkit
42+
```
43+
</TabItem>
44+
<TabItem value='yarn' label='yarn'>
45+
```
46+
yarn add commandkit
47+
```
48+
</TabItem>
49+
<TabItem value='pnpm' label='pnpm'>
50+
```
51+
pnpm install commandkit
52+
```
53+
</TabItem>
54+
<TabItem value='bun' label='bun'>
55+
```
56+
bun install commandkit
57+
```
58+
</TabItem>
59+
60+
</Tabs>
61+
62+
## Development version
63+
64+
To install the development version of CommandKit, run one of the following commands:
65+
66+
<Tabs>
67+
<TabItem value='npm' label='npm'>
68+
```
69+
npm install commandkit@dev
70+
```
71+
</TabItem>
72+
<TabItem value='yarn' label='yarn'>
73+
```
74+
yarn add commandkit@dev
75+
```
76+
</TabItem>
77+
<TabItem value='pnpm' label='pnpm'>
78+
```
79+
pnpm install commandkit@dev
80+
```
81+
</TabItem>
82+
<TabItem value='bun' label='bun'>
83+
```
84+
bun install commandkit@dev
85+
```
86+
</TabItem>
87+
88+
</Tabs>
89+
90+
:::warning
91+
The development version is likely to have bugs.
92+
:::
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
title: create-commandkit
3+
description: Create a new CommandKit application with the command-line utility.
4+
---
5+
6+
# create-commandkit
7+
8+
Besides installing CommandKit to your existing project, you can also start a new one with `create-commandkit` — a command-line utility used for creating new discord.js bots with CommandKit.
9+
10+
## Usage
11+
12+
If you want to create a new CommandKit application, simply run the following command:
13+
14+
```
15+
npm create commandkit@latest
16+
```
17+
18+
This will start the CLI in the current directory.
19+
20+
### Development version
21+
22+
Similar to the main package, you could try the `dev` version of create-commandkit:
23+
24+
:::warning
25+
The development version is likely to have bugs.
26+
:::
27+
28+
```
29+
npm create commandkit@dev
30+
```
31+
32+
## Prompts
33+
34+
When running create-commandkit, you should be asked the following questions:
35+
36+
- **Directory:** Defines where your project will be located. It defaults to the current working directory.
37+
- **Package Manager:** Lets you choose which package manager to use — npm, pnpm, or Yarn.
38+
- **Language ([Development version](#development-version) only):** The language to use for your project — JavaScript or TypeScript.
39+
- **Module Type:** Allows you to pick between CommonJS (using require and module.exports), and ESM (using import and export).
40+
- **Bot Token:** Asks you for your bot token, and writes it into the `.env` file where it will be stored.
41+
42+
After these questions are answered, your project solution should appear in the selected folder.
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
---
2+
title: CommandKit setup
3+
description: A simple overview of how to set up CommandKit with all the available options.
4+
---
5+
6+
import Tabs from '@theme/Tabs';
7+
import TabItem from '@theme/TabItem';
8+
9+
# CommandKit Setup
10+
11+
This is a simple overview of how to set up CommandKit with all the available options. You’d usually set this up in your entry file (e.g. `index.js`) where you have access to your Discord.js client object.
12+
13+
<Tabs>
14+
<TabItem value='cjs' label='CommonJS' default>
15+
```js title="src/index.js" {2, 13-23}
16+
const { Client, GatewayIntentBits } = require('discord.js');
17+
const { CommandKit } = require('commandkit');
18+
const path = require('path');
19+
20+
const client = new Client({
21+
intents: [
22+
GatewayIntentBits.Guilds,
23+
GatewayIntentBits.GuildMessages,
24+
GatewayIntentBits.MessageContent,
25+
],
26+
});
27+
28+
new CommandKit({
29+
client,
30+
commandsPath: path.join(__dirname, 'commands'),
31+
eventsPath: path.join(__dirname, 'events'),
32+
validationsPath: path.join(__dirname, 'validations'),
33+
devGuildIds: ['DEV_SERVER_ID_1', 'DEV_SERVER_ID_2'],
34+
devUserIds: ['DEV_USER_ID_1', 'DEV_USER_ID_2'],
35+
devRoleIds: ['DEV_ROLE_ID_1', 'DEV_ROLE_ID_2'],
36+
skipBuiltInValidations: true,
37+
bulkRegister: true,
38+
});
39+
40+
client.login('YOUR_TOKEN_HERE');
41+
```
42+
</TabItem>
43+
<TabItem value='esm' label='ESM'>
44+
```js title="src/index.js" {2, 16-26}
45+
import { Client, GatewayIntentBits } from 'discord.js';
46+
import { CommandKit } from 'commandkit';
47+
import { fileURLToPath } from 'url';
48+
import path from 'path';
49+
50+
const client = new Client({
51+
intents: [
52+
GatewayIntentBits.Guilds,
53+
GatewayIntentBits.GuildMessages,
54+
GatewayIntentBits.MessageContent
55+
],
56+
});
57+
58+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
59+
60+
new CommandKit({
61+
client,
62+
commandsPath: path.join(__dirname, 'commands'),
63+
eventsPath: path.join(__dirname, 'events'),
64+
validationsPath: path.join(__dirname, 'validations'),
65+
devGuildIds: ['DEV_SERVER_ID_1', 'DEV_SERVER_ID_2'],
66+
devUserIds: ['DEV_USER_ID_1', 'DEV_USER_ID_2'],
67+
devRoleIds: ['DEV_ROLE_ID_1', 'DEV_ROLE_ID_2'],
68+
skipBuiltInValidations: true,
69+
bulkRegister: true,
70+
});
71+
72+
client.login('YOUR_TOKEN_HERE');
73+
```
74+
</TabItem>
75+
<TabItem value='ts' label='TypeScript'>
76+
```ts title="src/index.ts" {2, 13-23}
77+
import { Client, GatewayIntentBits } from 'discord.js';
78+
import { CommandKit } from 'commandkit';
79+
import path from 'path';
80+
81+
const client = new Client({
82+
intents: [
83+
GatewayIntentBits.Guilds,
84+
GatewayIntentBits.GuildMessages,
85+
GatewayIntentBits.MessageContent
86+
],
87+
});
88+
89+
new CommandKit({
90+
client,
91+
commandsPath: path.join(__dirname, 'commands'),
92+
eventsPath: path.join(__dirname, 'events'),
93+
validationsPath: path.join(__dirname, 'validations'),
94+
devGuildIds: ['DEV_SERVER_ID_1', 'DEV_SERVER_ID_2'],
95+
devUserIds: ['DEV_USER_ID_1', 'DEV_USER_ID_2'],
96+
devRoleIds: ['DEV_ROLE_ID_1', 'DEV_ROLE_ID_2'],
97+
skipBuiltInValidations: true,
98+
bulkRegister: true,
99+
});
100+
101+
client.login('YOUR_TOKEN_HERE');
102+
```
103+
</TabItem>
104+
105+
</Tabs>
106+
107+
:::info
108+
Some Discord.js properties are only accessible using the correct intents.
109+
:::
110+
111+
## CommandKit options
112+
113+
### `client`
114+
115+
- Type: [`Client`](https://old.discordjs.dev/#/docs/discord.js/main/class/Client)
116+
117+
This is your Discord.js client object. This is required to register and handle application commands and events.
118+
119+
### `commandsPath` (optional)
120+
121+
- Type: `string`
122+
123+
This is the path to your commands directory. It's used to fetch, register, and listen for application commands.
124+
125+
### `eventsPath` (optional)
126+
127+
- Type: `string`
128+
129+
This is the path to your events directory. It's used to fetch and set event listeners based on the folder names inside of it.
130+
131+
### `validationsPath` (optional)
132+
133+
- Type: `string`
134+
135+
This is the path to your validations directory. It's used to fetch and call validation functions before running application commands.
136+
137+
### `devGuildIds` (optional)
138+
139+
- Type: `string[]`
140+
141+
This is a list of development server IDs. It's used to restrict commands marked with `devOnly` to specific servers.
142+
143+
If there is at least 1 guild ID provided, CommandKit will register any commands marked as `devOnly` inside the listed servers.
144+
145+
### `devUserIds` (optional)
146+
147+
- Type: `string[]`
148+
149+
This is a list of developer user IDs. It's used to restrict commands marked with `devOnly` to specific users.
150+
151+
Trying to execute a command when this is set to at-least 1 user ID will call a built-in validation function everytime to validate that the user running the command belongs to the provided `devUserIds` array.
152+
153+
### `devRoleIds` (optional)
154+
155+
- Type: `string[]`
156+
157+
This is a list of developer role IDs. It's used to restrict commands marked with `devOnly` to specific roles.
158+
159+
Trying to execute a command when this is set to at-least 1 role ID will call a built-in validation function everytime to validate that the user running the command has at least one of the provided roles.
160+
161+
### `skipBuiltInValidations` (optional)
162+
163+
- Type: `boolean`
164+
- Default: `false`
165+
166+
This is used to disable CommandKit's built-in validation functions. Setting this to `true` will ignore the default behaviour of validating who is running commands marked with `devOnly`.
167+
168+
### `bulkRegister` (optional)
169+
170+
- Type: `boolean`
171+
- Default: `false`
172+
173+
This is used to change the behaviour of how CommandKit loads application commands. By default it's one-by-one while comparing changes. Setting this option to `true` will load application commands all at once on every restart, and when [`reloadCommands()`](/docs/api-reference/classes/CommandKit#reloadcommands) is called.

0 commit comments

Comments
 (0)