feat(string-prompt): Adds string prompt to menu item
This commit is contained in:
parent
1d73ee8a78
commit
5c7c9c9f87
6 changed files with 164 additions and 26 deletions
|
|
@ -1,17 +1,44 @@
|
|||
import {Modal} from "./Modal";
|
||||
import {Interaction, MessageComponentInteraction, TextInputBuilder} from "discord.js";
|
||||
import {
|
||||
ActionRowBuilder,
|
||||
Interaction,
|
||||
MessageComponentInteraction,
|
||||
ModalSubmitInteraction,
|
||||
TextInputBuilder
|
||||
} from "discord.js";
|
||||
import {EventHandler} from "../../Events/EventHandler";
|
||||
|
||||
export type RequestResponse = {
|
||||
interaction: ModalSubmitInteraction,
|
||||
value: string
|
||||
}
|
||||
|
||||
export class Prompt extends Modal {
|
||||
constructor(eventHandler: EventHandler) {
|
||||
super(eventHandler);
|
||||
}
|
||||
|
||||
public async requestValue(
|
||||
label: string,
|
||||
field: TextInputBuilder,
|
||||
interaction: MessageComponentInteraction
|
||||
): Promise<string> {
|
||||
): Promise<RequestResponse> {
|
||||
const modal = this.getBuilder()
|
||||
.setTitle(label);
|
||||
|
||||
field.setCustomId("value");
|
||||
const actionRow = new ActionRowBuilder<TextInputBuilder>();
|
||||
actionRow.setComponents([field])
|
||||
modal.setComponents(actionRow);
|
||||
|
||||
await interaction.showModal(modal);
|
||||
const responseInteraction = await this.awaitResponse();
|
||||
responseInteraction.fields.getTextInputValue()
|
||||
const value = responseInteraction.fields.getTextInputValue("value");
|
||||
|
||||
return {
|
||||
value,
|
||||
interaction: responseInteraction
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue