class Collector

extends

EventEmitter
abstract
export abstract class Collector<Key, Value, Extras extends unknown[] = []> extends EventEmitter

Abstract class for defining a new Collector.

Constructors

constructor(
client: Client<true>
options?: CollectorOptions<[Value, ...Extras]>
)

Constructs a new instance of the Collector class

Type Parameters

Key

Value

optional
Extras? extends unknown[] = []

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

readonly
next : Promise<Value>

Returns a promise that resolves with the next collected element; rejects with collected elements if the collector finishes without receiving a next element

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: unknown[]
) : Key | null | Promise<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

abstract
dispose(
...args: unknown[]
) : 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

handleCollect(
...args: unknown[]
) : Promise<void>

Call this to handle an event as a collectable element. Accepts any event data as parameters.

handleDispose(
...args: unknown[]
) : Promise<void>

Call this to remove an element from the collection. Accepts any event data as parameters.

on<

EventKey extends keyof CollectorEventTypes<Key, Value, Extras>

>(
event: EventKey
listener: (...args: CollectorEventTypes<Key, Value, Extras>[EventKey]) => Awaitable<void>
) : this

once<

EventKey extends keyof CollectorEventTypes<Key, Value, Extras>

>(
event: EventKey
listener: (...args: CollectorEventTypes<Key, Value, Extras>[EventKey]) => Awaitable<void>
) : this

resetTimer() : void

Resets the collector's timeout and idle timer.

stop(
reason?: string
) : void

Stops this collector and emits the end event.

toJSON() : unknown

collect(
args: any
)

Emitted whenever an element is collected.

dispose(
args: any
)

Emitted whenever an element is disposed of.

end(
collected: Collection
reason: string
)

Emitted when the collector is finished collecting.

ignore(
args: any
)

Emitted whenever an element is not collected by the collector.