Kord Extensions Help

Custom Events

If you'd like to create your own events, you have two options:

  • Extend Kord's Event type. This is provided as an option mostly so that you can integrate other Kord-based libraries with Kord Extensions.

  • Extend the KordExEvent type, which itself extends Kord's Event type. This also extends the KordExKoinComponent type, providing Koin ⏳ access.

The KordExEvent type has an identical API to the Kord Event type.

public data class MyEvent( public val data: String ) : KordExEvent

Once you've constructed an event object, you can fire it using the send function that's part of the ExtensibleBot type. If you need to get a reference to this, you can do so via Koin ⏳.

class MyClass : KordExKoinComponent { val bot: ExtensibleBot by inject() fun myFunction() { val event = MyEvent("data") bot.send(event) } }

Rich Base Types

When an event deals with specific entity types, it's important that it implements the relevant rich base types.

Name

Parent Types

Description

GuildEvent

Base type for events that contain guild information. This must be provided in the form of a GuildBehavior object.

MemberEvent

GuildEvent, UserEvent

Base type for events that contain guild member information. This must be provided in the form of a MemberBehavior object.

MessageEvent

Base type for events that contain message information. This must be provided in the form of a MessageBehavior object.

RoleEvent

Base type for events that contain role information. This must be provided in the form of a RoleBehavior object.

UserEvent

Base type for events that contain user information. This must be provided in the form of a UserEvent object.

Last modified: 20 November 2024