Event collector for awaiting Discord gateway events.
Provides Discord.js-style await patterns for blocking on specific events
with filters and timeouts. Useful for interactive flows (confirmations,
paginated menus, quizzes, etc.).
Examples
# Await a single message from a specific user in a channel
case EDA.Collector.await(:MESSAGE_CREATE, fn msg ->
msg.channel_id == channel_id and msg.author["id"] == user_id
end, timeout: 30_000) do
{:ok, message} -> handle_response(message)
{:error, :timeout} -> send_timeout_message(channel_id)
end
# Await up to 5 reactions on a message
{:ok, reactions} = EDA.Collector.await(:MESSAGE_REACTION_ADD, fn r ->
r.message_id == msg_id
end, max: 5, timeout: 60_000)Events are fed into collectors via notify/2, called automatically by
EDA.Gateway.Events on every dispatched event.
Summary
Functions
Awaits one or more gateway events matching the given filter.
Returns a specification to start this module under a supervisor.
Notifies the collector of a new event. Called by EDA.Gateway.Events.
Functions
@spec await(atom() | [atom()], (term() -> boolean()), keyword()) :: {:ok, term()} | {:ok, [term()]} | {:error, :timeout}
Awaits one or more gateway events matching the given filter.
event_types can be a single atom or a list of atoms (e.g., :MESSAGE_CREATE
or [:MESSAGE_CREATE, :MESSAGE_UPDATE]).
Options
:timeout— max wait time in milliseconds (default:30_000):max— number of events to collect before returning (default:1)
Returns
{:ok, event}whenmaxis 1{:ok, [events]}whenmax> 1{:error, :timeout}if timeout expires before enough events are collected
Returns a specification to start this module under a supervisor.
See Supervisor.
Notifies the collector of a new event. Called by EDA.Gateway.Events.
This is a non-blocking cast. If the Collector GenServer is not running, the notification is silently ignored.