Skip to content

Commit 9770553

Browse files
committed
add message commands docs
1 parent 90d9768 commit 9770553

File tree

3 files changed

+71
-3
lines changed

3 files changed

+71
-3
lines changed

apps/website/docs/guide/02-commands/01-chat-input-commands.mdx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
title: Chat input commands
33
---
44

5+
Chat input commands, more commonly known as 'Slash Commands', are a
6+
way for users on Discord to perform actions using your bot.
7+
58
CommandKit provides a very simple way to manage your chat input
6-
(slash) commands, including registering them to the Discord API, as
7-
well as handling their execution.
9+
commands, including registering them to the Discord API, as well as
10+
handling their execution.
811

912
To create a new chat input command, create a new file in the
1013
`src/app/commands` directory with the name of the command. This guide

apps/website/docs/guide/02-commands/02-command-options-autocomplete.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ title: Options autocomplete
44

55
:::warning
66

7-
This feature is only available for chat input (slash) commands.
7+
This feature is only available for
8+
[chat input commands](./01-chat-input-commands.mdx).
89

910
:::
1011

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,67 @@
11
---
22
title: Message commands
33
---
4+
5+
Message commands, which are generally considered 'Legacy', are a way
6+
to run commands on Discord bots using regular messages. Before the
7+
introduction of
8+
[Slash/Chat Input Commands](./01-chat-input-commands.mdx), this was
9+
the primary way commands were handled. They were usually triggered by
10+
using a prefix set by the developer of the bot (for example: `!ping`).
11+
12+
:::warning
13+
14+
While CommandKit allows developers to create and handle message
15+
commands, it's important to note that Discord generally discourages
16+
message commands in favor of the more modern
17+
[Chat Input Commands](./01-chat-input-commands.mdx).
18+
19+
:::
20+
21+
Message commands, like all the other command types, live in your
22+
`src/app/commands` directory. To let CommandKit know that this is a
23+
message command, just export the `messageCommand` function.
24+
25+
```ts title="src/app/commands/ping.ts"
26+
import type { CommandData, MessageCommand } from 'commandkit';
27+
28+
export const command: CommandData = {
29+
name: 'ping',
30+
};
31+
32+
export const messageCommand: MessageCommand = async (ctx) => {
33+
await ctx.message.reply('Pong!');
34+
};
35+
```
36+
37+
:::tip
38+
39+
By default, your bot's prefix will be `!`. However, with CommandKit
40+
you can set custom prefixes, or even guild-based prefixes.
41+
[Read more](./05-custom-message-commands-prefix.mdx)
42+
43+
:::
44+
45+
## Message command options (arguments)
46+
47+
Since a message command - on a technical level - is just a string, the
48+
idea of message command options will be different compared to
49+
[chat input command](./01-chat-input-commands.mdx) options. Instead of
50+
getting parsed data, you'll essentially be dealing with string
51+
'arguments'.
52+
53+
```ts title="src/app/commands/ping.ts"
54+
import type { CommandData, MessageCommand } from 'commandkit';
55+
56+
export const command: CommandData = {
57+
name: 'ping',
58+
};
59+
60+
export const messageCommand: MessageCommand = async (ctx) => {
61+
const args = ctx.message.args(); // string[]
62+
};
63+
```
64+
65+
With the above command as an example, if a user on Discord runs
66+
`!ping arg1 arg2 arg3`, the value of `args` will equal
67+
`['arg1', 'arg2', 'arg3']`.

0 commit comments

Comments
 (0)