Skip to content

Commit 0bd131c

Browse files
authored
Merge pull request #19 from m1-dev/migrate-djs-commander
Documentation for migrating from DJS-Commander
2 parents ee5bbcf + 9c7cd48 commit 0bd131c

File tree

2 files changed

+117
-2
lines changed

2 files changed

+117
-2
lines changed

apps/docs/pages/docs/_meta.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
"commandkit-setup": "CommandKit Setup",
44
"command-file-setup": "Commands Setup",
55
"event-file-setup": "Events Setup",
6-
"validation-file-setup": "Validations Setup"
7-
}
6+
"validation-file-setup": "Validations Setup",
7+
"migrating-from-djs-commander": "Migrating from DJS-Commander"
8+
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
import { Callout } from 'nextra/components';
2+
3+
# Migrating from `DJS-Commander`
4+
5+
If you're trying to use CommandKit as a drop-in replacement for DJS-Commander, you'll need to make a few changes to your code.
6+
7+
<Callout type="warning">
8+
This guide is **not** introducing the features this library offers over DJS-Commander. It's just
9+
going over the changes you'll need to make to your code to get it working with this library.
10+
</Callout>
11+
12+
## Setting up the command handler
13+
14+
In DJS-Commander, you'd import and instantiate the `CommandHandler` class. The only difference with CommandKit is the name of the class. Instead of `CommandHandler`, it's called `CommandKit`.
15+
16+
```js
17+
const { CommandKit } = require('commandkit');
18+
19+
new CommandKit({
20+
client,
21+
commandsPath,
22+
eventsPath,
23+
});
24+
```
25+
26+
## Setting up development servers
27+
28+
In DJS-Commander only a single development server was supported, and it was setup under the property name `testServer` when instantiating `CommandHandler`.
29+
30+
```js
31+
new CommandHandler({
32+
client,
33+
commandsPath,
34+
eventsPath,
35+
testServer: '123456789012345678', //
36+
});
37+
```
38+
39+
In CommandKit, you can setup multiple development servers under the property name `devServerIds`
40+
41+
```js
42+
new CommandKit({
43+
client,
44+
commandsPath,
45+
eventsPath,
46+
devServerIds: ['123456789012345678', '876543210987654321'], //
47+
});
48+
```
49+
50+
However, this does not automatically register all the commands in those specific servers. By default, CommandKit will globally register all commands. If you want to register commands in specific servers, you'll need to use the `devOnly` property inside `options` from within the command file object.
51+
52+
```js
53+
module.exports = {
54+
data: {
55+
name: 'ping',
56+
description: 'Pong!',
57+
},
58+
59+
run: ({ interaction }) => {
60+
interaction.reply('Pong!');
61+
},
62+
63+
options: {
64+
devOnly: true, //
65+
},
66+
};
67+
```
68+
69+
This command will now be registered in your development server, however you won't be able to run this command as you haven't configure the developer user IDs. Yes, CommandKit has built in support for developer user IDs! You can set them up under the property name `devUserIds` when instantiating `CommandKit`.
70+
71+
```js
72+
new CommandKit({
73+
client,
74+
commandsPath,
75+
eventsPath,
76+
devServerIds: ['123456789012345678', '876543210987654321'],
77+
devUserIds: ['123456789012345678', '876543210987654321'], //
78+
});
79+
```
80+
81+
## Deleting commands
82+
83+
Deleting commands with CommandKit is a bit different from DJS-Commander's. In DJS-Commander you'd directly export the `deleted` property from the command object. In CommandKit, you're required to export the `deleted` property inside another object called `options`.
84+
85+
```js
86+
module.exports = {
87+
data: {
88+
name: 'ping',
89+
description: 'Pong!',
90+
},
91+
92+
run: ({ interaction }) => {
93+
interaction.reply('Pong!');
94+
},
95+
96+
deleted: true, //
97+
98+
options: {
99+
deleted: true, //
100+
},
101+
};
102+
```
103+
104+
## Updating validations parameters
105+
106+
In DJS-Commander, you'd get access to the `interaction` and `commandObj` in a specified order through the parameters. In CommandKit, you get access to the `interaction` and `commandObj` through an object.
107+
108+
```js
109+
// DJS-Commander
110+
module.exports = (interaction, commandObj) => {}; //
111+
112+
// CommandKit
113+
module.exports = ({ interaction, commandObj }) => {}; //
114+
```

0 commit comments

Comments
 (0)