fix: i dont know why it was like that

This commit is contained in:
MARCROCK22 2025-06-17 16:47:46 -04:00
parent db38f49ca9
commit 0608c7ad85

View File

@ -38,7 +38,10 @@ export interface CreateComponentCollectorResult {
callback: ComponentCallback<T>, callback: ComponentCallback<T>,
): void; ): void;
stop(reason?: string): void; stop(reason?: string): void;
waitFor<T extends CollectorInteraction = CollectorInteraction>(customId: UserMatches): Promise<T | null>; waitFor<T extends CollectorInteraction = CollectorInteraction>(
customId: UserMatches,
timeout?: number,
): Promise<T | null>;
resetTimeouts(): void; resetTimeouts(): void;
} }
@ -117,23 +120,24 @@ export class ComponentHandler extends BaseHandler {
this.createComponentCollector(messageId, channelId, guildId, options, old.components); this.createComponentCollector(messageId, channelId, guildId, options, old.components);
}); });
}, },
waitFor: customId => waitFor: (customId, timeout) =>
new Promise(resolve => { new Promise(resolve => {
const collector = this.values.get(messageId); const collector = this.values.get(messageId);
if (!collector) return resolve(null); if (!collector) return resolve(null);
let nodeTimeout: NodeJS.Timeout | undefined;
this.values.get(messageId)!.__run(customId, interaction => { this.values.get(messageId)!.__run(customId, interaction => {
this.clearValue(messageId); clearTimeout(nodeTimeout);
//@ts-expect-error generic //@ts-expect-error generic
resolve(interaction); resolve(interaction);
}); });
if (collector?.timeout) clearTimeout(collector.timeout); if (timeout && timeout > 0)
collector.timeout = setTimeout(() => { nodeTimeout = setTimeout(() => {
this.clearValue(messageId); resolve(null);
resolve(null); // by default 15 seconds in case user don't do anything
// by default 15 seconds in case user don't do anything }, timeout);
}, collector?.options?.timeout ?? 15_000);
}), }),
resetTimeouts: () => { resetTimeouts: () => {
this.resetTimeouts(messageId); this.resetTimeouts(messageId);