EventHandler

open class EventHandler<T : Event>(val extension: Extension) : KordExKoinComponent

Class representing an event handler. Event handlers react to a given Kord event.

You shouldn't need to use this class directly - instead, create an Extension and use the Extension.event to register your event handler, by overriding the Extension.setup function.

Parameters

extension

The Extension that registered this event handler.

Constructors

Link copied to clipboard
constructor(extension: Extension)

Properties

Link copied to clipboard
var coroutineScope: CoroutineScope

Coroutine scope used to launch this event handler when handling a new event.

Link copied to clipboard
Link copied to clipboard
open val kord: Kord

Current Kord instance powering the bot.

Link copied to clipboard

Cached locale variable, stored and retrieved by getLocale.

Link copied to clipboard

Sentry adapter, for easy access to Sentry functions.

Functions

Link copied to clipboard
fun action(action: suspend EventContext<T>.() -> Unit)

Define what will happen when your event handler is invoked.

Link copied to clipboard
suspend fun call(event: T)

Execute this event handler, given an event.

Link copied to clipboard
fun check(vararg checks: CheckWithCache<T>): Boolean

Define a check which must pass for the event handler to be executed.

Overloaded check function to allow for DSL syntax.

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

Get the associated Koin instance.

Link copied to clipboard
suspend fun Event.getLocale(): Locale

Resolve the locale for the given event.

Link copied to clipboard
suspend fun Event.translate(key: Key, replacements: Array<Any?> = arrayOf()): String
suspend fun Event.translate(key: Key, replacements: Map<String, Any?>): String

Given a translation key, return the translation for the locale provided by the bot's configured locale resolvers.

Link copied to clipboard
fun validate()

An internal function used to ensure that all of an event handler's required arguments are present.