-
Notifications
You must be signed in to change notification settings - Fork 59
/
prompt.ts
55 lines (50 loc) · 1.2 KB
/
prompt.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import {
ComponentType,
MessageComponentInteraction,
TextInputStyle,
} from 'discord.js'
import { randomUUID } from 'node:crypto'
/**
* Prompt for a single text input in Discord.
*
* @param interaction - the interaction that will trigger the prompt
* @returns a submission object or undefined if the prompt timed out. You should reply to `submission.interaction` with a message.
*/
export async function prompt(
interaction: MessageComponentInteraction,
title: string,
label: string,
) {
const promptId = randomUUID() as string
await interaction.showModal({
customId: promptId,
title,
components: [
{
type: ComponentType.ActionRow,
components: [
{
customId: 'text',
label,
type: ComponentType.TextInput,
style: TextInputStyle.Short,
required: true,
},
],
},
],
})
const submitted = await interaction
.awaitModalSubmit({
time: 5 * 60_000,
filter: (index) => index.customId === promptId,
})
.catch(() => null)
if (!submitted) {
return
}
return {
text: submitted.fields.getTextInputValue('text'),
interaction: submitted,
}
}