Skip to content

Commit f152ef4

Browse files
committed
docs: update select menu component examples
1 parent 6403808 commit f152ef4

File tree

2 files changed

+66
-32
lines changed

2 files changed

+66
-32
lines changed

apps/test-bot/src/app/commands/(interactions)/commandkit.tsx

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import {
66
ChatInputCommandContext,
77
StringSelectMenu,
88
StringSelectMenuOption,
9+
OnStringSelectMenuKitSubmit,
10+
ChatInputCommand,
911
} from 'commandkit';
1012
import { ButtonStyle, MessageFlags } from 'discord.js';
1113

@@ -42,17 +44,37 @@ export const command: CommandData = {
4244
// );
4345
// }
4446

45-
export async function chatInput({ interaction }: ChatInputCommandContext) {
46-
const row = (
47+
const handleSelect: OnStringSelectMenuKitSubmit = async (
48+
interaction,
49+
context,
50+
) => {
51+
const selections = interaction.values;
52+
await interaction.reply({
53+
content: `You selected: ${selections.join(', ')}`,
54+
flags: MessageFlags.Ephemeral,
55+
});
56+
context.dispose();
57+
};
58+
59+
export const chatInput: ChatInputCommand = async ({ interaction }) => {
60+
const selectMenu = (
4761
<ActionRow>
48-
<Button disabled customId="disabled">
49-
Cannot Click
50-
</Button>
51-
<Button customId="enabled">Can Click</Button>
62+
<StringSelectMenu
63+
placeholder="Choose multiple options"
64+
minValues={1}
65+
maxValues={3}
66+
onSelect={handleSelect}
67+
>
68+
<StringSelectMenuOption label="Pizza" value="pizza" emoji="🍕" />
69+
<StringSelectMenuOption label="Burger" value="burger" emoji="🍔" />
70+
<StringSelectMenuOption label="Pasta" value="pasta" emoji="🍝" />
71+
<StringSelectMenuOption label="Sushi" value="sushi" emoji="🍣" />
72+
</StringSelectMenu>
5273
</ActionRow>
5374
);
5475

5576
await interaction.reply({
56-
components: [row],
77+
content: 'Select your favorite foods (1-3 options):',
78+
components: [selectMenu],
5779
});
58-
}
80+
};

apps/website/docs/guide/04-jsx-components/02-discord-components-v1/03-select-menu.mdx

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@ The most common type of select menu that allows users to select from
1111
predefined string options:
1212

1313
```tsx title="src/app/commands/string-select.tsx"
14-
import type {
15-
ChatInputCommand,
16-
OnStringSelectMenuKitSubmit,
17-
} from 'commandkit';
1814
import {
15+
type ChatInputCommand,
16+
type OnStringSelectMenuKitSubmit,
1917
ActionRow,
2018
StringSelectMenu,
2119
StringSelectMenuOption,
@@ -31,6 +29,8 @@ const handleSelect: OnStringSelectMenuKitSubmit = async (
3129
content: `You selected: ${selection}`,
3230
flags: MessageFlags.Ephemeral,
3331
});
32+
33+
// Clean up the select menu context
3434
context.dispose();
3535
};
3636

@@ -77,11 +77,12 @@ export const chatInput: ChatInputCommand = async ({
7777
Allows users to select a channel from the server:
7878

7979
```tsx title="src/app/commands/channel-select.tsx"
80-
import type {
81-
ChatInputCommand,
82-
OnChannelSelectMenuKitSubmit,
80+
import {
81+
type ChatInputCommand,
82+
type OnChannelSelectMenuKitSubmit,
83+
ActionRow,
84+
ChannelSelectMenu,
8385
} from 'commandkit';
84-
import { ActionRow, ChannelSelectMenu } from 'commandkit';
8586
import { MessageFlags } from 'discord.js';
8687

8788
const handleSelect: OnChannelSelectMenuKitSubmit = async (
@@ -93,6 +94,8 @@ const handleSelect: OnChannelSelectMenuKitSubmit = async (
9394
content: `Selected channel: <#${channel}>`,
9495
flags: MessageFlags.Ephemeral,
9596
});
97+
98+
// Clean up the select menu context
9699
context.dispose();
97100
};
98101

@@ -120,11 +123,12 @@ export const chatInput: ChatInputCommand = async ({
120123
Allows users to select a role from the server:
121124

122125
```tsx title="src/app/commands/role-select.tsx"
123-
import type {
124-
ChatInputCommand,
125-
OnRoleSelectMenuKitSubmit,
126+
import {
127+
type ChatInputCommand,
128+
type OnRoleSelectMenuKitSubmit,
129+
ActionRow,
130+
RoleSelectMenu,
126131
} from 'commandkit';
127-
import { ActionRow, RoleSelectMenu } from 'commandkit';
128132
import { MessageFlags } from 'discord.js';
129133

130134
const handleSelect: OnRoleSelectMenuKitSubmit = async (
@@ -136,6 +140,8 @@ const handleSelect: OnRoleSelectMenuKitSubmit = async (
136140
content: `Selected role: <@&${role}>`,
137141
flags: MessageFlags.Ephemeral,
138142
});
143+
144+
// Clean up the select menu context
139145
context.dispose();
140146
};
141147

@@ -163,11 +169,12 @@ export const chatInput: ChatInputCommand = async ({
163169
Allows users to select a user from the server:
164170

165171
```tsx title="src/app/commands/user-select.tsx"
166-
import type {
167-
ChatInputCommand,
168-
OnUserSelectMenuKitSubmit,
172+
import {
173+
type ChatInputCommand,
174+
type OnUserSelectMenuKitSubmit,
175+
ActionRow,
176+
UserSelectMenu,
169177
} from 'commandkit';
170-
import { ActionRow, UserSelectMenu } from 'commandkit';
171178
import { MessageFlags } from 'discord.js';
172179

173180
const handleSelect: OnUserSelectMenuKitSubmit = async (
@@ -179,6 +186,8 @@ const handleSelect: OnUserSelectMenuKitSubmit = async (
179186
content: `Selected user: <@${user}>`,
180187
flags: MessageFlags.Ephemeral,
181188
});
189+
190+
// Clean up the select menu context
182191
context.dispose();
183192
};
184193

@@ -206,11 +215,12 @@ export const chatInput: ChatInputCommand = async ({
206215
Allows users to select a user or role from the server:
207216

208217
```tsx title="src/app/commands/mentionable-select.tsx"
209-
import type {
210-
ChatInputCommand,
211-
OnMentionableSelectMenuKitSubmit,
218+
import {
219+
type ChatInputCommand,
220+
type OnMentionableSelectMenuKitSubmit,
221+
ActionRow,
222+
MentionableSelectMenu,
212223
} from 'commandkit';
213-
import { ActionRow, MentionableSelectMenu } from 'commandkit';
214224
import { MessageFlags } from 'discord.js';
215225

216226
const handleSelect: OnMentionableSelectMenuKitSubmit = async (
@@ -222,6 +232,8 @@ const handleSelect: OnMentionableSelectMenuKitSubmit = async (
222232
content: `Selected: <@${mentionable}>`,
223233
flags: MessageFlags.Ephemeral,
224234
});
235+
236+
// Clean up the select menu context
225237
context.dispose();
226238
};
227239

@@ -250,11 +262,9 @@ You can allow multiple selections by setting the `minValues` and
250262
`maxValues` properties:
251263

252264
```tsx title="src/app/commands/multi-select.tsx"
253-
import type {
254-
ChatInputCommand,
255-
OnStringSelectMenuKitSubmit,
256-
} from 'commandkit';
257265
import {
266+
type ChatInputCommand,
267+
type OnStringSelectMenuKitSubmit,
258268
ActionRow,
259269
StringSelectMenu,
260270
StringSelectMenuOption,
@@ -270,6 +280,8 @@ const handleSelect: OnStringSelectMenuKitSubmit = async (
270280
content: `You selected: ${selections.join(', ')}`,
271281
flags: MessageFlags.Ephemeral,
272282
});
283+
284+
// Clean up the select menu context
273285
context.dispose();
274286
};
275287

0 commit comments

Comments
 (0)