Class: MessageCollector

MessageCollector

Collects messages on a channel. Will automatically stop if the channel (`'channelDelete'`) or guild (`'guildDelete'`) are deleted.

Constructor

new MessageCollector(channel, filter, options)

Parameters:
Name Type Description
channel TextChannel | DMChannel The channel
filter CollectorFilter The filter to be applied to this collector
options MessageCollectorOptions The options to be applied to this collector
Source:
Fires:
  • MessageCollector#event:message

Extends

Members

(private, nullable) _idletimeout :Timeout

Timeout for cleanup due to inactivity
Type:
  • Timeout
Overrides:
Source:

(private, nullable) _timeout :Timeout

Timeout for cleanup
Type:
  • Timeout
Overrides:
Source:

channel :TextBasedChannel

The channel
Type:
Source:

(readonly) client :Client

The client that instantiated this Collector
Type:
Overrides:
Source:

collected :Collection

The items collected by this collector
Type:
  • Collection
Overrides:
Source:

ended :boolean

Whether this collector has finished collecting
Type:
  • boolean
Overrides:
Source:

filter :CollectorFilter

The filter applied to this collector
Type:
Overrides:
Source:

(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
Type:
  • Promise
Overrides:
Source:

options :CollectorOptions

The options of this collector
Type:
Overrides:
Source:

received :number

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

Methods

(private) _handleChannelDeletion(channel) → {void}

Handles checking if the channel has been deleted, and if so, stops the collector with the reason 'channelDelete'.
Parameters:
Name Type Description
channel GuildChannel The channel that was deleted
Source:
Returns:
Type
void

(private) _handleGuildDeletion(guild) → {void}

Handles checking if the guild has been deleted, and if so, stops the collector with the reason 'guildDelete'.
Parameters:
Name Type Description
guild Guild The guild that was deleted
Source:
Returns:
Type
void

checkEnd()

Checks whether the collector should end, and if so, ends it.
Overrides:
Source:

(private) collect(message) → {Snowflake}

Handles a message for possible collection.
Parameters:
Name Type Description
message Message The message that could be collected
Overrides:
Source:
Returns:
Type
Snowflake

dispose(message) → {Snowflake}

Handles a message for possible disposal.
Parameters:
Name Type Description
message Message The message that could be disposed of
Overrides:
Source:
Returns:
Type
Snowflake

(private) endReason() → {string}

Checks after un/collection to see if the collector is done.
Overrides:
Source:
Returns:
Type
string

handleCollect(…args)

Call this to handle an event as a collectable element. Accepts any event data as parameters.
Parameters:
Name Type Attributes Description
args * <repeatable>
The arguments emitted by the listener
Overrides:
Source:
Fires:

handleDispose(…args)

Call this to remove an element from the collection. Accepts any event data as parameters.
Parameters:
Name Type Attributes Description
args * <repeatable>
The arguments emitted by the listener
Overrides:
Source:
Fires:

resetTimer(optionsopt)

Resets the collectors timeout and idle timer.
Parameters:
Name Type Attributes Description
options Object <optional>
Options
Properties
Name Type Attributes Description
time number <optional>
How long to run the collector for in milliseconds
idle number <optional>
How long to stop the collector after inactivity in milliseconds
Overrides:
Source:

stop(reasonopt)

Stops this collector and emits the `end` event.
Parameters:
Name Type Attributes Default Description
reason string <optional>
'user' The reason this collector is ending
Overrides:
Source:
Fires:

Events

collect

Emitted whenever a message is collected.
Parameters:
Name Type Description
message Message The message that was collected
Overrides:
Source:

dispose

Emitted whenever a message is disposed of.
Parameters:
Name Type Description
message Message The message that was disposed of
Overrides:
Source:

end

Emitted when the collector is finished collecting.
Parameters:
Name Type Description
collected Collection The elements collected by the collector
reason string The reason the collector ended
Overrides:
Source: