Collectors let you wait for one or more messages or reactions that satisfy a condition, without blocking the main event handler. They are created via client methods and operate as independent async tasks.Documentation Index
Fetch the complete documentation index at: https://docs.devimorris.tech/llms.txt
Use this file to discover all available pages before exploring further.
EndReason
Returned alongside the result from.collect(). Indicates why collection ended.
| Variant | Description |
|---|---|
EndReason::Time | The timeout set in time expired. |
EndReason::Limit | The limit set in max was reached. |
EndReason::User | The channel was closed - client destroyed or collector dropped. |
MessageCollector
Collects messages from a specified channel.MessageCollectorOptions
| Field | Type | Description |
|---|---|---|
channel_id | String | ID of the channel to collect messages from. |
filter | Option<MessageFilter> | Predicate function Fn(&ApiMessage) -> bool. Messages that don’t pass are ignored. |
time | Option<Duration> | Maximum wait time. When elapsed, the collector ends with EndReason::Time. |
max | Option<usize> | Maximum number of messages to collect. When reached - EndReason::Limit. |
Creating
&mut Client. Registers an internal sender through which the client delivers incoming messages to the collector.
Collecting
.collect() consumes the collector. If you need multiple independent collection passes - create a new collector each time.Example: wait for the next message from a user
Example: wait for the next message from a user
Example: collect 5 messages within 60 seconds
Example: collect 5 messages within 60 seconds
ReactionCollector
Collects reactions on a specified message.ReactionCollectorOptions
| Field | Type | Description |
|---|---|---|
message_id | String | ID of the message to collect reactions from. |
channel_id | String | ID of the channel the message is in. |
filter | Option<ReactionFilter> | Predicate function Fn(&CollectedReaction) -> bool. |
time | Option<Duration> | Maximum wait time. |
max | Option<usize> | Maximum number of reactions to collect. |
Creating
Collecting
CollectedReaction
Structure delivered to the collector from theMessageReactionAdd event.
| Field | Type | Description |
|---|---|---|
message_id | String | Message ID. |
channel_id | String | Channel ID. |
guild_id | Option<String> | Guild ID. None in DMs. |
user_id | String | ID of the user who reacted. |
emoji_name | String | Emoji name or Unicode character. |
emoji_id | Option<String> | Custom emoji ID. None for Unicode. |
emoji_animated | bool | Whether the emoji is animated. |
key()
user_id:emoji_name:emoji_id (for custom emoji) or user_id:emoji_name (for Unicode). Useful for deduplication.
Example: confirm an action via reaction
Example: confirm an action via reaction
Example: poll - collect all reactions within 10 seconds
Example: poll - collect all reactions within 10 seconds
Architecture
Collectors work viampsc::UnboundedSender. When a collector is created, the client stores its sender internally. On every MessageCreate or MessageReactionAdd, the client fans out data to all registered senders.
