Startup & Shutdown#
It is possible to execute code when the client has started up or shut down, this can be done via the @Client.add_startup_hook and @Client.add_shutdown_hook respectively.
The startup hook is a great place to initialize resources that require an async context and/or the bot to be started. It is called after the client has already synced all commands and the underlying bot has fully started.
The shutdown hook is where you can clean up any remaining resources, close connections, etc. It is called when the bot has started to shut down.
Lifecycle Events#
Gateway only
This section is only relevant to those using a Gateway client, as REST bots cannot receive events.
If you prefer handling your client's lifecycle via events, you may listen for arc.StartedEvent or arc.StoppingEvent respectively. These are dispatched immediately after the lifecycle hooks were processed, guaranteeing that the client is in the right state.
What is the difference between arc.StartedEvent and hikari.StartedEvent?
arc.StartedEvent fires after the client has already synced all commands and initialized internally, which happens after hikari.StartedEvent fires, therefore it is the recommended to use arc.StartedEvent over hikari.StartedEvent.