mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-14 10:33:30 +01:00
feat(Collector): better types for events (#6058)
Co-authored-by: Antonio Román <kyradiscord@gmail.com>
This commit is contained in:
4
typings/index.d.ts
vendored
4
typings/index.d.ts
vendored
@@ -391,10 +391,10 @@ export abstract class Collector<K, V, F extends unknown[] = []> extends EventEmi
|
|||||||
public abstract collect(...args: unknown[]): K | null | Promise<K | null>;
|
public abstract collect(...args: unknown[]): K | null | Promise<K | null>;
|
||||||
public abstract dispose(...args: unknown[]): K | null;
|
public abstract dispose(...args: unknown[]): K | null;
|
||||||
|
|
||||||
public on(event: 'collect' | 'dispose', listener: (...args: unknown[]) => Awaited<void>): this;
|
public on(event: 'collect' | 'dispose', listener: (...args: [V, ...F]) => Awaited<void>): this;
|
||||||
public on(event: 'end', listener: (collected: Collection<K, V>, reason: string) => Awaited<void>): this;
|
public on(event: 'end', listener: (collected: Collection<K, V>, reason: string) => Awaited<void>): this;
|
||||||
|
|
||||||
public once(event: 'collect' | 'dispose', listener: (...args: unknown[]) => Awaited<void>): this;
|
public once(event: 'collect' | 'dispose', listener: (...args: [V, ...F]) => Awaited<void>): this;
|
||||||
public once(event: 'end', listener: (collected: Collection<K, V>, reason: string) => Awaited<void>): this;
|
public once(event: 'end', listener: (collected: Collection<K, V>, reason: string) => Awaited<void>): this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,11 +8,14 @@ import {
|
|||||||
MessageActionRow,
|
MessageActionRow,
|
||||||
MessageAttachment,
|
MessageAttachment,
|
||||||
MessageButton,
|
MessageButton,
|
||||||
|
MessageCollector,
|
||||||
MessageEmbed,
|
MessageEmbed,
|
||||||
|
MessageReaction,
|
||||||
NewsChannel,
|
NewsChannel,
|
||||||
Options,
|
Options,
|
||||||
PartialTextBasedChannelFields,
|
PartialTextBasedChannelFields,
|
||||||
Permissions,
|
Permissions,
|
||||||
|
ReactionCollector,
|
||||||
Serialized,
|
Serialized,
|
||||||
ShardClientUtil,
|
ShardClientUtil,
|
||||||
ShardingManager,
|
ShardingManager,
|
||||||
@@ -489,3 +492,14 @@ notPropertyOf(user, 'lastMessage');
|
|||||||
notPropertyOf(user, 'lastMessageId');
|
notPropertyOf(user, 'lastMessageId');
|
||||||
notPropertyOf(guildMember, 'lastMessage');
|
notPropertyOf(guildMember, 'lastMessage');
|
||||||
notPropertyOf(guildMember, 'lastMessageId');
|
notPropertyOf(guildMember, 'lastMessageId');
|
||||||
|
|
||||||
|
// Test collector event parameters
|
||||||
|
declare const messageCollector: MessageCollector;
|
||||||
|
messageCollector.on('collect', (...args) => {
|
||||||
|
assertType<[Message]>(args);
|
||||||
|
});
|
||||||
|
|
||||||
|
declare const reactionCollector: ReactionCollector;
|
||||||
|
reactionCollector.on('dispose', (...args) => {
|
||||||
|
assertType<[MessageReaction, User]>(args);
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user