Skip to content

hikari.events.lifetime_events#

Events that are bound to the lifetime of an application.

These are types of hooks that can be invoked on startup or shutdown, which can be used to initialize other resources, fetch information, and perform checks.

StartedEvent #

Bases: Event

Event that is triggered after the application has started.

This will only fire once per startup, so is suitable for opening database connections and other resources that need to be initialized within a coroutine function.

If you want to do something before the application connects, you should consider using hikari.events.lifetime_events.StartingEvent instead.

app class-attribute instance-attribute #

app: RESTAware = field(metadata={SKIP_DEEP_COPY: True})

App instance for this application.

StartingEvent #

Bases: Event

Event that is triggered before the application connects to Discord.

This will only fire once per startup, so is suitable for opening database connections and other resources that need to be initialized within a coroutine function.

Warning

The application will not proceed to connect to Discord until all event handlers for this event have completed/terminated. This prevents the risk of race conditions occurring (e.g. allowing message events to try to access a database that has not yet connected fully).

If you want to do something after the application has initialized, you should consider using hikari.events.lifetime_events.StartedEvent instead.

app class-attribute instance-attribute #

app: RESTAware = field(metadata={SKIP_DEEP_COPY: True})

App instance for this application.

StoppedEvent #

Bases: Event

Event that is triggered once the application has disconnected.

This will only fire once per close, so is suitable for closing database connections and other resources that need to be closed within a coroutine function.

Warning

The application will not proceed to leave the run call until all event handlers for this event have completed/terminated. This prevents the risk of race conditions occurring where a script may terminate the process before a callback can occur.

If you want to do something when the application is preparing to shut down, but before any connection to Discord is closed, you should consider using hikari.events.lifetime_events.StoppingEvent instead.

app class-attribute instance-attribute #

app: RESTAware = field(metadata={SKIP_DEEP_COPY: True})

App instance for this application.

StoppingEvent #

Bases: Event

Event that is triggered as soon as the application is requested to close.

This will fire before the connection is physically disconnected.

This will only fire once per close, so is suitable for closing database connections and other resources that need to be closed within a coroutine function.

Warning

The application will not proceed to disconnect from Discord until all event handlers for this event have completed/terminated. This prevents the risk of race conditions occurring from code that relies on a connection still being available to complete.

If you want to do something after the disconnection has occurred, you should consider using hikari.events.lifetime_events.StoppedEvent instead.

app class-attribute instance-attribute #

app: RESTAware = field(metadata={SKIP_DEEP_COPY: True})

App instance for this application.