diff --git a/packages/discord.js/src/structures/interfaces/Collector.js b/packages/discord.js/src/structures/interfaces/Collector.js index c0793fd03..8f232d7d5 100644 --- a/packages/discord.js/src/structures/interfaces/Collector.js +++ b/packages/discord.js/src/structures/interfaces/Collector.js @@ -236,7 +236,7 @@ class Collector extends EventEmitter { */ async *[Symbol.asyncIterator]() { const queue = []; - const onCollect = item => queue.push(item); + const onCollect = (...item) => queue.push(item); this.on('collect', onCollect); try { diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index b782f755d..5ba158fa7 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -670,7 +670,7 @@ export abstract class Collector extends EventEmi public handleDispose(...args: unknown[]): Promise; public stop(reason?: string): void; public resetTimer(options?: CollectorResetTimerOptions): void; - public [Symbol.asyncIterator](): AsyncIterableIterator; + public [Symbol.asyncIterator](): AsyncIterableIterator<[V, ...F]>; public toJSON(): unknown; protected listener: (...args: any[]) => void; diff --git a/packages/discord.js/typings/index.test-d.ts b/packages/discord.js/typings/index.test-d.ts index d95161eea..52477639b 100644 --- a/packages/discord.js/typings/index.test-d.ts +++ b/packages/discord.js/typings/index.test-d.ts @@ -794,11 +794,23 @@ messageCollector.on('collect', (...args) => { expectType<[Message]>(args); }); +(async () => { + for await (const value of messageCollector) { + expectType<[Message]>(value); + } +})(); + declare const reactionCollector: ReactionCollector; reactionCollector.on('dispose', (...args) => { expectType<[MessageReaction, User]>(args); }); +(async () => { + for await (const value of reactionCollector) { + expectType<[MessageReaction, User]>(value); + } +})(); + // Make sure the properties are typed correctly, and that no backwards properties // (K -> V and V -> K) exist: expectType<'messageCreate'>(Constants.Events.MESSAGE_CREATE); @@ -1169,6 +1181,12 @@ collector.on('end', (collection, reason) => { expectType(reason); }); +(async () => { + for await (const value of collector) { + expectType<[Interaction, ...string[]]>(value); + } +})(); + expectType>(shard.eval(c => c.readyTimestamp)); // Test audit logs