feat: modal#waitFor

This commit is contained in:
Socram03 2025-06-19 04:26:09 -04:00
parent 6e037ae964
commit 35f1904920

View File

@ -1,4 +1,5 @@
import type { RestOrArray } from '../common'; import type { RestOrArray } from '../common';
import { ModalSubmitInteraction } from '../structures';
import { import {
type APIActionRowComponent, type APIActionRowComponent,
type APIModalInteractionResponseCallbackData, type APIModalInteractionResponseCallbackData,
@ -89,6 +90,22 @@ export class Modal<T extends ModalBuilderComponents = TextInput> {
return this; 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. * Converts the modal to JSON format.
* @returns The modal data in JSON format. * @returns The modal data in JSON format.