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.

Module Contents#

class hikari.events.lifetime_events.StartingEvent[source]#

Bases: hikari.events.base_events.Event

Event that is triggered before the application connects to Discord.

This will only fire once per bot.run / bot.start, 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 StartedEvent instead.

class hikari.events.lifetime_events.StartedEvent[source]#

Bases: hikari.events.base_events.Event

Event that is triggered after the application has started.

This will only fire once per bot.run / bot.start, 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 StartingEvent instead.

class hikari.events.lifetime_events.StoppingEvent[source]#

Bases: hikari.events.base_events.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 bot.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 StoppedEvent instead.

class hikari.events.lifetime_events.StoppedEvent[source]#

Bases: hikari.events.base_events.Event

Event that is triggered once the application has disconnected.

This will only fire once per bot.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 bot.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 StoppingEvent instead.