ExtensibleBot

An extensible bot, wrapping a Kord instance.

This is your jumping-off point. ExtensibleBot provides a system for managing extensions, commands and event handlers. Either subclass ExtensibleBot or use it as-is if it suits your needs.

You shouldn't construct this class directly - use the builder pattern via the companion object's invoke method: ExtensibleBot(token) { extensions { add(::MyExtension) } }.

Parameters

settings

Bot builder object containing the bot's settings.

token

Token for connecting to Discord.

Constructors

Link copied to clipboard
constructor(settings: ExtensibleBotBuilder, token: String)

Properties

Link copied to clipboard
val autoCompleteCoroutineContext: CoroutineDispatcher
Link copied to clipboard
open val eventHandlers: MutableList<EventHandler<out Event>>

A list of all registered event handlers.

Link copied to clipboard
open val events: SharedFlow<Any>

A Flow representing a combined set of Kord events and Kord Extensions events.

Link copied to clipboard

A map of the names of all loaded Extensions to their instances.

Link copied to clipboard
val interactionCoroutineContext: CoroutineDispatcher
Link copied to clipboard
open override var locking: Boolean

Set this to true to lock execution with a Mutex.

Link copied to clipboard
open override var mutex: Mutex?

Mutex object to use for locking.

Link copied to clipboard

Functions

Link copied to clipboard
open suspend fun addDefaultExtensions()

This function adds all of the default extensions when the bot is being set up.

Link copied to clipboard
inline fun <T : Event> addEventHandler(handler: EventHandler<T>)

Directly register an EventHandler to this bot.

Link copied to clipboard
open suspend fun addExtension(builder: () -> Extension)

Install an Extension to this bot.

Link copied to clipboard
open suspend fun close()

Stop the bot by unloading extensions, shutting down Kord, and removing its Koin context.

Link copied to clipboard
inline fun <T> findExtension(): T?

Find the first loaded extension that is an instance of the type provided in T.

Link copied to clipboard
inline fun <T> findExtensions(): List<T>

Find all loaded extensions that are instances of the type provided in T.

Link copied to clipboard
open override fun getKoin(): Koin

Get the associated Koin instance.

Link copied to clipboard
open suspend fun loadExtension(extension: String)

Reload an unloaded Extension from this bot, by name.

Link copied to clipboard
open suspend fun lock()

Lock the mutex, if locking is enabled - suspending until it's unlocked.

Link copied to clipboard
inline fun <T : Event> on(launch: Boolean = true, scope: CoroutineScope = kordRef, noinline consumer: suspend T.() -> Unit): Job

Subscribe to an event. You shouldn't need to use this directly, but it's here just in case.

Link copied to clipboard
inline fun <T : Event> registerListenerForHandler(handler: EventHandler<T>): Job

Directly register an EventHandler to this bot.

Link copied to clipboard
open suspend fun registerListeners()
Link copied to clipboard
open fun removeEventHandler(handler: EventHandler<out Event>): Boolean

Directly remove a registered EventHandler from this bot.

Link copied to clipboard
inline suspend fun send(event: Event, filter: Boolean = true)

Submit an event, triggering any relevant event handlers.

Link copied to clipboard
open suspend fun start()

Start up the bot and log into Discord.

Link copied to clipboard
open fun startAsync(): Job

Start up the bot and log into Discord, but launched via Kord's coroutine scope.

Link copied to clipboard
open suspend fun stop()

Stop the bot by logging out Kord.

Link copied to clipboard
open suspend fun unloadExtension(extension: String)

Unload an installed Extension from this bot, by name.

Link copied to clipboard
open fun unlock()

Unlock the mutex, if it's locked.

Link copied to clipboard
inline suspend fun <T : Event> ExtensibleBot.waitFor(timeout: Duration? = null, noinline condition: suspend T.() -> Boolean = { true }): T?

Return the first received event that matches the condition.

Link copied to clipboard
open suspend fun <T> withLock(body: suspend () -> T)

Lock the mutex (if locking is enabled), call the supplied callable, and unlock.