Skip to content

Commit 430d70d

Browse files
committed
setup typedef path
1 parent 263c660 commit 430d70d

File tree

11 files changed

+232
-6
lines changed

11 files changed

+232
-6
lines changed

apps/nextra-docs/pages/_meta.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,9 @@
66
"docs": {
77
"title": "Documentation",
88
"type": "page"
9+
},
10+
"typedef": {
11+
"title": "Typedefs",
12+
"type": "page"
913
}
1014
}
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,175 @@
1+
import { Tabs } from 'nextra/components';
2+
13
# Commands Setup
4+
5+
CommandKit supports both slash commands and context menu commands. Since both have the same triggers (interactions) and similar command structure, they are both stored and handled from the same commands directory.
6+
7+
### Slash Command
8+
9+
Here's an example `/ping` slash command which replies with "Pong!"
10+
11+
<Tabs items={['CommonJS', 'ESM', 'TypeScript']}>
12+
<Tabs.Tab>
13+
```js filename="commands/misc/ping.js" copy
14+
module.exports = {
15+
data: {
16+
name: 'ping',
17+
description: 'Pong!',
18+
},
19+
20+
run: ({ interaction, client, handler }) => {
21+
interaction.reply(`:ping_pong: Pong! ${client.ws.ping}ms`);
22+
},
23+
24+
options: {
25+
devOnly: true,
26+
guildOnly: true,
27+
userPermissions: ['Administrator', 'AddReactions'],
28+
botPermissions: ['Administrator', 'AddReactions'],
29+
deleted: false,
30+
},
31+
};
32+
```
33+
</Tabs.Tab>
34+
<Tabs.Tab>
35+
```js filename="commands/misc/ping.js" copy
36+
export const data = {
37+
name: 'ping',
38+
description: 'Pong!',
39+
},
40+
41+
export function run({ interaction, client, handler }) {
42+
interaction.reply(`:ping_pong: Pong! ${client.ws.ping}ms`);
43+
},
44+
45+
export const options = {
46+
devOnly: true,
47+
guildOnly: true,
48+
userPermissions: ['Administrator', 'AddReactions'],
49+
botPermissions: ['Administrator', 'AddReactions'],
50+
deleted: false,
51+
},
52+
```
53+
</Tabs.Tab>
54+
<Tabs.Tab>
55+
```ts filename="commands/misc/ping.ts" copy
56+
import type { CommandData, SlashCommandProps, CommandOptions } from 'commandkit';
57+
58+
export const data: CommandData = {
59+
name: 'ping',
60+
description: 'Pong!',
61+
},
62+
63+
export function run({ interaction, client, handler }: SlashCommandProps) {
64+
interaction.reply(`:ping_pong: Pong! ${client.ws.ping}ms`);
65+
},
66+
67+
export const options: CommandOptions = {
68+
devOnly: true,
69+
guildOnly: true,
70+
userPermissions: ['Administrator', 'AddReactions'],
71+
botPermissions: ['Administrator', 'AddReactions'],
72+
deleted: false,
73+
},
74+
```
75+
</Tabs.Tab>
76+
77+
</Tabs>
78+
79+
### Context Menu Command
80+
81+
Here's an example `content` command which replies with the content of the target message.
82+
83+
<Tabs items={['CommonJS', 'ESM', 'TypeScript']}>
84+
<Tabs.Tab>
85+
```js filename="commands/misc/content.js" copy
86+
const { CommandType } = require('commandkit');
87+
88+
module.exports = {
89+
data: {
90+
name: 'content',
91+
type: CommandType.Message,
92+
},
93+
94+
run: ({ interaction, client, handler }) => {
95+
interaction.reply(`The message is: ${interaction.targetMessage}`);
96+
},
97+
98+
options: {
99+
devOnly: true,
100+
guildOnly: true,
101+
userPermissions: ['Administrator', 'AddReactions'],
102+
botPermissions: ['Administrator', 'AddReactions'],
103+
deleted: false,
104+
},
105+
};
106+
```
107+
</Tabs.Tab>
108+
<Tabs.Tab>
109+
```js filename="commands/misc/content.js" copy
110+
import { CommandType } from 'commandkit';
111+
112+
export const data = {
113+
name: 'content',
114+
type: CommandType.Message,
115+
},
116+
117+
export function run({ interaction, client, handler }) {
118+
interaction.reply(`The message is: ${interaction.targetMessage}`);
119+
},
120+
121+
export const options = {
122+
devOnly: true,
123+
guildOnly: true,
124+
userPermissions: ['Administrator', 'AddReactions'],
125+
botPermissions: ['Administrator', 'AddReactions'],
126+
deleted: false,
127+
},
128+
```
129+
</Tabs.Tab>
130+
<Tabs.Tab>
131+
```ts filename="commands/misc/content.ts" copy
132+
import { CommandType, type CommandData, type ContextMenuCommandProps, type CommandOptions } from 'commandkit';
133+
134+
export const data: CommandData = {
135+
name: 'content',
136+
type: CommandType.Message,
137+
},
138+
139+
export function run({ interaction, client, handler }: ContextMenuCommandProps) {
140+
interaction.reply(`The message is: ${interaction.targetMessage}`);
141+
},
142+
143+
export const options: CommandOptions = {
144+
devOnly: true,
145+
guildOnly: true,
146+
userPermissions: ['Administrator', 'AddReactions'],
147+
botPermissions: ['Administrator', 'AddReactions'],
148+
deleted: false,
149+
},
150+
```
151+
</Tabs.Tab>
152+
153+
</Tabs>
154+
155+
## Properties and Methods
156+
157+
### `data`
158+
159+
- Type: [`CommandData`](/typedef/CommandData) | [`SlashCommandBuilder`](https://discord.js.org/docs/packages/builders/main/SlashCommandBuilder:Class) | [`ContextMenuCommandBuilder`](https://discord.js.org/docs/packages/builders/main/ContextMenuCommandBuilder:Class)
160+
161+
This property contains the command's structural information, and is required to register and handle commands.
162+
163+
### `run`
164+
165+
- Type: `void`
166+
167+
- Props Type: [`SlashCommandProps`](/typedef/SlashCommandProps) | [`ContextMenuCommandProps`](/typedef/ContextMenuCommandProps)
168+
169+
This function will be called when the command is executed.
170+
171+
### `options` (optional)
172+
173+
- Type: [`CommandOptions`](/typedef/CommandOptions)
174+
175+
This property contains the command's registration/handling behaviour.

apps/nextra-docs/pages/docs/commandkit-setup.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Steps, Tabs, Callout } from 'nextra/components';
1+
import { Tabs, Callout } from 'nextra/components';
22

33
# CommandKit Setup
44

apps/nextra-docs/pages/docs/handler-properties.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@ When a CommandKit class has been instantiated, it's easier to refer to the resul
44

55
### `commands`
66

7-
- Type: `CommandObject[]`
7+
- Type: [`CommandObject[]`](/typedef/CommandObject)
88

99
An array of all the command objects that CommandKit is handling. This includes all the properties and methods that are also set outside of CommandKit's configuration. It does however not include the `run` method since CommandKit handles that internally.
1010

1111
### `commandsPath` (development version)
1212

13-
- Type: `string | undefined`
13+
- Type: `string` | `undefined`
1414

1515
The path to the commands directory which was set when [instantiating CommandKit](/docs/commandkit-setup).
1616

1717
### `eventsPath` (development version)
1818

19-
- Type: `string | undefined`
19+
- Type: `string` | `undefined`
2020

2121
The path to the events directory which was set when [instantiating CommandKit](/docs/commandkit-setup).
2222

2323
### `validationsPath` (development version)
2424

25-
- Type: `string | undefined`
25+
- Type: `string` | `undefined`
2626

2727
The path to the validations directory which was set when [instantiating CommandKit](/docs/commandkit-setup).
2828

apps/nextra-docs/pages/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default function Home() {
2828
A Discord.js handler for commands and events.
2929
</p>
3030

31-
<div className="flex items-center justify-center gap-3 mt-5 md:justify-start">
31+
<div className="flex items-center justify-center gap-3 mt-10 md:justify-start">
3232
<Link href='/docs/installation' className="font-semibold bg-[#ec6068] py-2 px-4 rounded-full">Documentation</Link>
3333

3434
<Link href='https://github.com/underctrl-io/commandkit' className="font-semibold bg-blue-500 py-2 px-4 rounded-full" target='_blank' target="_blank" rel="noopener noreferrer">GitHub</Link>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# CommandData
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# CommandObject
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { Callout } from 'nextra/components';
2+
3+
# CommandOptions
4+
5+
### `devOnly`
6+
7+
- Type: `boolean`
8+
9+
This determines whether the command should only be registered in development guilds and be executed by the bot developers.
10+
11+
### `guildOnly`
12+
13+
<Callout type="error">
14+
This will soon be deprecated. Use `dm_permission` in your command `data` instead.
15+
</Callout>
16+
17+
- Type: `boolean`
18+
19+
This determines whether the command should only be handled in guilds.
20+
21+
### `userPermissions`
22+
23+
- Type: [`PermissionResolvable`](https://old.discordjs.dev/#/docs/discord.js/main/typedef/PermissionResolvable)
24+
25+
This determines whether the user has the required permissions to execute the command. This is checked against the user's permissions in the guild where the command was executed (if any).
26+
27+
### `botPermissions`
28+
29+
- Type: [`PermissionResolvable`](https://old.discordjs.dev/#/docs/discord.js/main/typedef/PermissionResolvable)
30+
31+
This determines whether the bot has the required permissions to execute the command. This is checked against the bot's permissions in the guild where the command was executed (if any).
32+
33+
### `deleted`
34+
35+
- Type: [`PermissionResolvable`](https://old.discordjs.dev/#/docs/discord.js/main/typedef/PermissionResolvable)
36+
37+
This determines whether the command should be deleted on the next reload.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# ContextMenuCommandProps
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# SlashCommandProps

0 commit comments

Comments
 (0)