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