Skip to content

MessageCollector

classe · Source

Collects messages on a channel. Will automatically stop if the channel (channelDelete), thread (threadDelete), or guild (guildDelete) is deleted.

Extends: Collector

Constructor

new MessageCollector(channel: TextBasedChannels, options: MessageCollectorOptions)

Parameters

NameTypeDescription
channelTextBasedChannelsThe channel
optionsMessageCollectorOptionsThe options to be applied to this collector

Properties

channel

channel: TextBasedChannels

The channel Source

received

received: number

Total number of messages that were received in the channel during message collection Source

endReason

readonly · nullable

endReason: string

The reason this collector has ended with, or null if it hasn't ended yet Source

client

readonly

client: Client

The client that instantiated this Collector Source

filter

filter: CollectorFilter

The filter applied to this collector Source

options

options: CollectorOptions

The options of this collector Source

collected

collected: Collection

The items collected by this collector Source

ended

ended: boolean

Whether this collector has finished collecting Source

_timeout

nullable · private

_timeout: Timeout

Timeout for cleanup Source

_idletimeout

nullable · private

_idletimeout: Timeout

Timeout for cleanup due to inactivity Source

next

readonly

next: Promise

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

Methods

collect

private

collect(message: Message): Snowflake

Handles a message for possible collection. Parameters

NameTypeDescription
messageMessageThe message that could be collected

Returns: SnowflakeSource

dispose

dispose(message: Message): Snowflake

Handles a message for possible disposal. Parameters

NameTypeDescription
messageMessageThe message that could be disposed of

Returns: SnowflakeSource

_handleChannelDeletion

private

_handleChannelDeletion(channel: GuildChannel): void

Handles checking if the channel has been deleted, and if so, stops the collector with the reason 'channelDelete'. Parameters

NameTypeDescription
channelGuildChannelThe channel that was deleted

Returns: voidSource

_handleThreadDeletion

private

_handleThreadDeletion(thread: ThreadChannel): void

Handles checking if the thread has been deleted, and if so, stops the collector with the reason 'threadDelete'. Parameters

NameTypeDescription
threadThreadChannelThe thread that was deleted

Returns: voidSource

_handleGuildDeletion

private

_handleGuildDeletion(guild: Guild): void

Handles checking if the guild has been deleted, and if so, stops the collector with the reason 'guildDelete'. Parameters

NameTypeDescription
guildGuildThe guild that was deleted

Returns: voidSource

handleCollect

async

async handleCollect(args: *): Promise<void>

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

NameTypeDescription
args*The arguments emitted by the listener

Returns: Promise<void>Source

handleDispose

async

async handleDispose(args: *): Promise<void>

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

NameTypeDescription
args*The arguments emitted by the listener

Returns: Promise<void>Source

stop

stop(reason?: string)

Stops this collector and emits the end event. Parameters

NameTypeDescription
reason?stringThe reason this collector is ending Default: 'user'.
Source

resetTimer

resetTimer(options?: CollectorResetTimerOptions)

Resets the collector's timeout and idle timer. Parameters

NameTypeDescription
options?CollectorResetTimerOptionsOptions for resetting
Source

checkEnd

checkEnd(): boolean

Checks whether the collector should end, and if so, ends it. Returns: boolean — Whether the collector ended or not Source

Events

collect

collect: unknown

Emitted whenever a message is collected. Parameters

NameTypeDescription
messageMessageThe message that was collected
Source

dispose

dispose: unknown

Emitted whenever a message is disposed of. Parameters

NameTypeDescription
messageMessageThe message that was disposed of
Source

end

end: unknown

Emitted when the collector is finished collecting. Parameters

NameTypeDescription
collectedCollectionThe elements collected by the collector
reasonstringThe reason the collector ended
Source

Unofficial software. Not affiliated with or supported by Discord.