berconpy.AsyncEventDispatcher

class berconpy.AsyncEventDispatcher

Bases: EventDispatcher

Implements the EventDispatcher interface for asyncio.

Methods

add_listener(event, func)

Adds a listener for a given event, e.g.

listen([event])

A decorator shorthand to add a listener for a given event, e.g.

remove_listener(event, func)

Removes a listener from a given event, e.g.

wait_for(event, *[, check, timeout])

Waits for a specific event to occur and returns the result.

add_listener(event, func)

Adds a listener for a given event, e.g. "on_login".

See the Event Reference for a list of supported events.

Parameters:
listen(event=None)

A decorator shorthand to add a listener for a given event, e.g. "on_login".

Parameters:

event (Optional[str]) – The event to listen for. If None, the function name is used as the event name.

Return type:

Callable[[TypeVar(T)], TypeVar(T)]

remove_listener(event, func)

Removes a listener from a given event, e.g. "on_login".

This method should be a no-op if the given event and function does not match any registered listener.

Parameters:
async wait_for(event, *, check=None, timeout=None)

Waits for a specific event to occur and returns the result.

This allows handling one-shot events in a simpler manner than with persistent listeners.

Parameters:
  • event (str) – The event to wait for, e.g. "login" and "on_login".

  • check (Union[Callable[..., Coroutine], Callable, None]) – An optional predicate function to use as a filter. This can be either a regular or an asynchronous function. The function should accept the same arguments that the event normally takes.

  • timeout (Union[float, int, None]) – An optional timeout for the function. If this is provided and the function times out, an asyncio.TimeoutError is raised.

Returns:

The same arguments received in the event.

Raises:

asyncio.TimeoutError – The timeout was exceeded while waiting.