Abstract

Collector

export abstract class Collector<Key, Value, Extras extends unknown[] = []> extends EventEmitter
export abstract class Collector<Key, Value, Extras extends unknown[] = []> extends EventEmitter
Abstract class for defining a new Collector.

Extends

EventEmitter
NameConstraintsOptionalDefaultDescription
KeyNoNone
ValueNoNone
Extrasunknown[]Yes[]None
constructor(client, options?)
Constructs a new instance of the Collector class
NameTypeOptionalDescription
clientClient<true>NoNone
optionsCollectorOptions<[Value, ...Extras]>YesNone
collect
Emitted whenever an element is collected.
NameTypeOptionalDescription
argsanyNoThe arguments emitted by the listener
dispose
Emitted whenever an element is disposed of.
NameTypeOptionalDescription
argsanyNoThe arguments emitted by the listener
end
Emitted when the collector is finished collecting.
NameTypeOptionalDescription
collectedCollectionNoThe elements collected by the collector
reasonstringNoThe reason the collector ended
ignore
Emitted whenever an element is not collected by the collector.
NameTypeOptionalDescription
argsanyNoThe arguments emitted by the listener
Readonly
client:Client
The client that instantiated this Collector
collected:Collection<Key, Value>
The items collected by this collector
ended:boolean
Whether this collector has finished collecting
Readonly
endReason:string | null
The reason this collector has ended with, or null if it hasn't ended yet
filter:CollectorFilter<[Value, ...Extras]>
The filter applied to this collector
Readonly
lastCollectedAt:Date | null
The Date at which this collector last collected an item
lastCollectedTimestamp:number | null
The timestamp at which this collector last collected an item
Protected
listener:(...args: any[]) => void
options:CollectorOptions<[Value, ...Extras]>
The options of this collector
[Symbol.asyncIterator]():AsyncIterableIterator<[Value, ...Extras]>
checkEnd():boolean
Checks whether the collector should end, and if so, ends it.
Returns
Whether the collector ended or not
Abstract
collect(...args):Awaitable<Key | null>
Handles incoming events from the handleCollect function. Returns null if the event should not be collected, or returns an object describing the data that should be stored.
Returns
Data to insert into collection, if any
NameTypeOptionalDescription
...argsunknown[]NoAny args the event listener emits
Abstract
dispose(...args):Key | null
Handles incoming events from the handleDispose. Returns null if the event should not be disposed, or returns the key that should be removed.
Returns
Key to remove from the collection, if any
NameTypeOptionalDescription
...argsunknown[]NoAny args the event listener emits
handleCollect(...args):Promise<void>
Call this to handle an event as a collectable element. Accepts any event data as parameters.
NameTypeOptionalDescription
...argsunknown[]NoThe arguments emitted by the listener
handleDispose(...args):Promise<void>
Call this to remove an element from the collection. Accepts any event data as parameters.
NameTypeOptionalDescription
...argsunknown[]NoThe arguments emitted by the listener
on(event, listener):this
NameTypeOptionalDescription
eventEventKeyNoNone
listener(...args: CollectorEventTypes<Key, Value, Extras>[EventKey]) => voidNoNone
once(event, listener):this
NameTypeOptionalDescription
eventEventKeyNoNone
listener(...args: CollectorEventTypes<Key, Value, Extras>[EventKey]) => voidNoNone
resetTimer(options?):void
Resets the collector's timeout and idle timer.
NameTypeOptionalDescription
optionsCollectorResetTimerOptionsYesOptions for resetting
stop(reason?):void
Stops this collector and emits the end event.
NameTypeOptionalDescription
reasonstringYesThe reason this collector is ending
toJSON():unknown