You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: apps/website/docs/guide/01-getting-started/02-setup-commandkit.mdx
+25-4
Original file line number
Diff line number
Diff line change
@@ -5,20 +5,41 @@ description: Setup a new CommandKit project manually, or using the create-comman
5
5
6
6
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:
7
7
8
-
```bash npm2yarn
8
+
```sh npm2yarn
9
9
npx create-commandkit@latest
10
10
```
11
11
12
12
This will start the CLI in the current directory which will help you quickly setup a base CommandKit project.
13
13
14
-
## Development version
14
+
## Project structure
15
+
16
+
By using the CLI to create a base project, you should get a project structure that looks like this:
15
17
16
-
If you'd like to try the latest development builds, you can use the `@dev` tag when setting up a CommandKit project using the CLI.
18
+
```
19
+
.
20
+
├── src/
21
+
│ ├── app/
22
+
│ │ ├── commands/
23
+
│ │ │ └── ping.ts
24
+
│ │ └── events/
25
+
│ │ └── ready/
26
+
│ │ └── log.ts
27
+
│ └── app.ts
28
+
├── .env
29
+
├── .gitignore
30
+
├── commandkit.config.ts
31
+
├── package.json
32
+
└── tsconfig.json
33
+
```
34
+
35
+
## Development version
17
36
18
37
:::warning
19
38
The development version is likely to have bugs.
20
39
:::
21
40
22
-
```bash npm2yarn
41
+
If you'd like to try the latest development builds, you can use the `@dev` tag like so:
Copy file name to clipboardExpand all lines: apps/website/docs/guide/01-getting-started/03-setup-commandkit-manually.mdx
+50-69
Original file line number
Diff line number
Diff line change
@@ -6,128 +6,109 @@ description: Learn how to install CommandKit.
6
6
importTabsfrom'@theme/Tabs';
7
7
importTabItemfrom'@theme/TabItem';
8
8
9
-
First of all, create a `commandkit.config.ts` at the root of your project. This file is used to configure CommandKit and its plugins.
9
+
If you don't want to use the CLI to automatically generate a base CommandKit project, you can integrate CommandKit manually into your application.
10
10
11
-
```ts
11
+
:::info
12
+
While this guide primarily uses TypeScript, you can alternatively use JavaScript files to follow along if that's what you're comfortable with (e.g. `commandkit.config.js`, `app.js`, etc)
13
+
:::
14
+
15
+
## Configuration file
16
+
17
+
To get started, create a file called `commandkit.config.ts` at the root of your project. This file is used to configure CommandKit and its plugins.
18
+
19
+
```ts title="commandkit.config.ts"
12
20
import { defineConfig } from'commandkit';
13
21
14
22
exportdefaultdefineConfig({});
15
23
```
16
24
17
-
Then, create a `src` folder and add `app.ts`file inside it.
25
+
## Entrypoint file
18
26
19
-
:::info
20
-
You can also use `.js` files instead of `.ts`. CommandKit supports both JavaScript and TypeScript out of the box.
21
-
:::
27
+
Then, create a folder called `src`, followed by a file called `app.ts` inside it. The file should look like this:
22
28
23
-
The `app.ts` file is the entrypoint of your bot. This file exports your discord.js client.
24
-
25
-
```ts
29
+
```ts title="src/app.ts"
26
30
import { Client } from'discord.js';
27
31
28
32
const client =newClient({
29
-
intents: [...],
33
+
intents: ['Guilds', 'GuildMembers'],
30
34
});
31
35
32
-
// must export the client here
36
+
// must export the `client` here
33
37
exportdefaultclient;
34
38
```
35
39
36
-
You don't need to call `client.login()` as commandkit will do that for you. You should store your bot token in `.env` file under `DISCORD_TOKEN` or `TOKEN` variable.
40
+
With the current entrypoint file created, it's important to understand that:
41
+
42
+
1. The `app.ts` file is the entrypoint for this application. This file **must** export your discord.js client instance.
43
+
2. You don't have to call `client.login()` as CommandKit will handle that for you.
44
+
3. You should store your bot token as an environment variable with either `DISCORD_TOKEN` or `TOKEN` as the name.
37
45
38
-
Now, lets create a simple command. Create a `src/app/commands` folder and add `ping.ts` file inside it.
46
+
## Adding commands
39
47
40
-
```ts
48
+
To add a command, create a folder inside the `src/app` directory called `commands` and create your command file (e.g. `ping.ts`). This example will use a simple ping/pong command which will register as a chat input (slash) and message (legacy) command.
This command will reply with `Pong!` when the user types `/ping` or `!ping` in the chat.
59
-
60
-
:::info
61
-
You can override the default prefix for message commands using:
62
-
63
-
```ts
64
-
import { commandkit } from'commandkit';
65
-
66
-
commandkit.setPrefixResolver(async (message) => {
67
-
// you can use `message` to fetch guild specific prefixes if needed
68
-
return'?';
69
-
});
70
-
```
71
-
72
-
An example of this could be:
67
+
This command will reply with "Pong!" when the user runs the `/ping` slash command, or sends `!ping` in the chat.
73
68
74
-
```ts
75
-
import { commandkit, cacheTag } from'commandkit';
76
-
import { database } from'../database.ts';
77
-
78
-
// this function's result will be automatically cached
79
-
asyncfunction fetchGuildPrefix(guildId:string) {
80
-
'use cache';
81
-
82
-
cacheTag(`prefix:${guildId}`);
83
-
84
-
const setting =awaitdatabase.findUnique({
85
-
where: { guildId },
86
-
select: { prefix: true },
87
-
});
88
-
89
-
// if no prefix is found, return the default prefix
90
-
returnsetting?.prefix??'!';
91
-
}
92
-
93
-
commandkit.setPrefixResolver((message) => {
94
-
returnfetchGuildPrefix(message.guildId);
95
-
});
96
-
```
97
-
98
-
You can also return array of prefixes.
69
+
:::tip
70
+
Prefixes for your message (legacy) commands can be changed. Learn more [here](/docs/next/guide/resolve-message-commands-prefix).
99
71
:::
100
72
101
-
Now, lets run the bot. You can use `commandkit dev` to start the bot in development mode. This will automatically reload the bot when you make changes to your code.
73
+
## Running the app in development
102
74
103
-
```sh
75
+
To run your application in development mode, you can use the `commandkit dev` command in your terminal. This will automatically reload the bot when you make changes to your code.
76
+
77
+
```sh npm2yarn
104
78
npx commandkit dev
105
79
```
106
80
107
-
When running in development mode, CommandKit will generate a `.commandkit` folder in your project directory. This folder contains the compiled files used in development mode. You should not commit this folder to your version control system. You should add it to your `.gitignore` file.
81
+
:::warning
82
+
When running in development mode, CommandKit will generate a `.commandkit` folder in the root of your project. This folder contains the compiled files used in development mode. You should not commit this folder to your version control system by making sure you add it to your `.gitignore` file.
83
+
:::
108
84
109
-
## Production build
85
+
## Building for production
110
86
111
87
When you are ready to deploy your bot, you can use `commandkit build` to create a production build of your bot. This will create a `dist` folder in your project directory containing the compiled files.
112
88
113
89
```sh
114
90
npx commandkit build
115
91
```
116
92
117
-
## Starting the bot in production mode
93
+
:::warning
94
+
After running your build script, CommandKit will generate a `.dist` folder in the root of your project. This folder contains the compiled files used for production. You should not commit this folder to your version control system by making sure you add it to your `.gitignore` file.
95
+
:::
96
+
97
+
## Running the app in production
118
98
119
-
You can use `commandkit start` to start the bot in production mode. This will load the environment variables from `.env` file in your project directory.
99
+
You can use `commandkit start` to start the bot in production mode. This will load the environment variables from the `.env` file in the root of your project directory.
120
100
121
101
```sh
122
102
npx commandkit start
123
103
```
124
104
125
-
If you want to manually start the bot in production mode, you can use the following command:
105
+
:::info
106
+
If you want to manually start the bot in production mode, you can alternatively use the following command:
126
107
127
108
```sh
128
109
node dist/index.js
129
110
```
130
111
131
-
:::info
132
-
The `index.js` file is autogenerated by `CommandKit`.
112
+
The `dist/index.js` file is generated by CommandKit.
0 commit comments