44 lines
No EOL
1.1 KiB
TypeScript
44 lines
No EOL
1.1 KiB
TypeScript
import {Modal} from "./Modal";
|
|
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<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();
|
|
const value = responseInteraction.fields.getTextInputValue("value");
|
|
|
|
return {
|
|
value,
|
|
interaction: responseInteraction
|
|
};
|
|
|
|
}
|
|
} |