Skip to content

Commit 90d9768

Browse files
committed
add context menu command docs
1 parent d338b45 commit 90d9768

File tree

2 files changed

+78
-1
lines changed

2 files changed

+78
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ In your chat input command options, autocomplete allows users on
1212
Discord to see a list of suggested choices based on what they're
1313
actively typing.
1414

15-
## Autocomplete with CommandKit
15+
## Managing autocomplete choices
1616

1717
In addition to registering your application commands, CommandKit can
1818
also handle any options you mark as 'autocomplete'. This means that
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,80 @@
11
---
22
title: Context menu commands
33
---
4+
5+
Context menu commands allows users on Discord to run commands by
6+
either referencing a message or a user. Context menu commands can be
7+
grouped to either 'Message' or 'User' context menu commands.
8+
9+
Alongside chat input commands, you can use CommandKit to also register
10+
and handle context menu commands.
11+
12+
Context menu commands live in the same directory as your chat input
13+
commands. To begin, create a command file in your `src/app/commands`
14+
directory.
15+
16+
This guide will create 2 simple `report-message` and `report-user`
17+
commands. It's not an actual reporting system, but it should make
18+
understanding the nature of these context menu commands easier.
19+
20+
## Message context menu command
21+
22+
```ts title="src/app/commands/report-message.ts"
23+
import type {
24+
CommandData,
25+
MessageContextMenuCommand,
26+
} from 'commandkit';
27+
import { MessageFlags } from 'discord.js';
28+
29+
export const command: CommandData = {
30+
name: 'report-message',
31+
description: 'Report a message to moderators.',
32+
};
33+
34+
export const messageContextMenu: MessageContextMenuCommand = async ({
35+
interaction,
36+
}) => {
37+
const content = interaction.targetMessage.content;
38+
39+
// you could add your message reporting logic here
40+
41+
await interaction.reply({
42+
content: `You have reported the following message: ${content}`,
43+
flags: MessageFlags.Ephemeral,
44+
});
45+
};
46+
```
47+
48+
By just exporting the `messageContextMenu` function from your command
49+
file, CommandKit will properly update your command type before
50+
registering it to the Discord API. You don't have to manually set a
51+
`type` in your `command` object, as you would with most command
52+
handlers.
53+
54+
## User context menu command
55+
56+
The logic for registering and handling user context menu commands is
57+
very similar to message context menu commands.
58+
59+
```ts title="src/app/commands/report-user.ts"
60+
import type { CommandData, UserContextMenuCommand } from 'commandkit';
61+
import { MessageFlags } from 'discord.js';
62+
63+
export const command: CommandData = {
64+
name: 'report-user',
65+
description: 'Report a user to moderators.',
66+
};
67+
68+
export const userContextMenu: UserContextMenuCommand = async ({
69+
interaction,
70+
}) => {
71+
const userId = interaction.targetUser.id;
72+
73+
// you could add your user reporting logic here
74+
75+
await interaction.reply({
76+
content: `You have reported a user with the ID: ${userId}`,
77+
flags: MessageFlags.Ephemeral,
78+
});
79+
};
80+
```

0 commit comments

Comments
 (0)