event_handler#

class wyvern.api.event_handler.EventHandler(*, bot: GatewayBot, listeners: dict[type[Event], list[EventListener]] = {})[source]#

Bases: object

Class handling dispatches and containing of the event listeners. An instance of this class is bound to the GatewayBot to handle events.

add_listener(lsnr: EventListener) None[source]#

Adds a listener to the container.

Parameters:

lsnr (EventListener) – The listener to add.

listeners: dict[type[Event], list[EventListener]]#

Mapping of Event types to list of EventListener s listening to the event.

class wyvern.api.event_handler.EventListener(*, type: type[Event], max_trigger: int | Undefined = <wyvern.utils.consts.Undefined object>, callback: types.EventListenerCallbackT, bot: GatewayBot | Undefined = <wyvern.utils.consts.Undefined object>)[source]#

Bases: object

Represents an event listener, the callback of this class gets triggered whenever the event this listener is bound to gets triggered.

callback: types.EventListenerCallbackT#

The callback for listener.

max_trigger: int | Undefined#

Maximum number of times this event can get triggered.

type: type[Event]#

Type of event this listener listens to.

wyvern.api.event_handler.listener(event: type[Event], *, max_trigger: int | Undefined = <wyvern.utils.consts.Undefined object>) Callable[[types.EventListenerCallbackT], EventListener][source]#

Used to create an EventListener.

Parameters:
  • event (type[Event]) – Class of the event this listener is bound to.

  • max_trigger (int) – Maximum trigger limit of the event callback.

Returns:

The listener that was created.

Return type:

EventListener