Kord Extensions Help

Hooks

The hooks builder allows you to register blocks of code to be executed at various stages of your bot's lifecycle. This has a number of important use-cases, which will be explored below.

ExtensibleBot(TOKEN) { // ... hooks { kordShutdownHook = true beforeKoinSetup { loadModule { single { Database() } bind Database::class } } } }

Builders

The following builders relate to extension loading states.

Name

Receiver

Description

beforeExtensionsAdded

ExtensibleBot

Run during startup, before any registered extensions are loaded.

extensionAdded

Run whenever an extension is loaded, at any point in the bot's lifecycle.

afterExtensionsAdded

ExtensibleBot

Run during startup, after all registered extensions are loaded.

The following builders relate to Koin setup progress. You can learn more about Koin in our dedicated Koin documentation, which explains how you should use it and what Kord Extensions does differently to the norm.

Name

Description

beforeKoinSetup

Run during startup, after Koin has been started, but before the default Koin modules have been registered. This is a great place to register any extra Koin modules you'll need.

afterKoinSetup

Run during startup, after the default Koin modules have been registered.

The following builders relate to the bot lifecycle itself.

Name

Receiver

Description

created

ExtensibleBot

Run during startup, right after the ExtensibleBot object has been created, and before its setup function has been run.

setup

ExtensibleBot

Run during startup, right after the ExtensibleBot's setup function has been run.

beforeStart

ExtensibleBot

Run during startup, just before the ExtensibleBot tries to connect to Discord. This hook will also be run if the ExtensibleBot has been stopped and restarted via the relevant functions.

Properties

Name

Type

Default

Description

kordShutdownHook

Boolean

true

Whether to register Kord's shutdown hook, which formally disconnects from the gateway when the process shuts down.

Last modified: 03 September 2024