From 35f190492051f104700b7f65240639f3b2254ffa Mon Sep 17 00:00:00 2001 From: Socram03 Date: Thu, 19 Jun 2025 04:26:09 -0400 Subject: [PATCH] feat: modal#waitFor --- src/builders/Modal.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/builders/Modal.ts b/src/builders/Modal.ts index 7a3a71f..150e037 100644 --- a/src/builders/Modal.ts +++ b/src/builders/Modal.ts @@ -1,4 +1,5 @@ import type { RestOrArray } from '../common'; +import { ModalSubmitInteraction } from '../structures'; import { type APIActionRowComponent, type APIModalInteractionResponseCallbackData, @@ -89,6 +90,22 @@ export class Modal { return this; } + waitFor(func: ModalSubmitCallback, timeout: number): this { + this.run( + interaction => + new Promise(resolve => { + const timer = setTimeout(() => { + resolve(null); + }, timeout); + func(interaction).then((data: ModalSubmitInteraction) => { + clearTimeout(timer); + resolve(data); + }); + }), + ); + return this; + } + /** * Converts the modal to JSON format. * @returns The modal data in JSON format.