EventListeners - kordlib/kordx.commands GitHub Wiki
Most sufficiently complex Discord bots will end up interacting with more than just MessageCreateEvent
events.
For this, kordx.commands.kord
introduces the EventPlug
.
EventPlugs are Plugs that allow you to listen to Kord's Events, behaving in a similar fashion to Kord's Kord#on
.
val onMemberJoin = on<MemberJoinEvent> {
member.getDmChannel().createMessage("Hello ${member.mention}!")
}
Wether it's a good idea to DM users on join is something we'll leave to you to ponder about.
EventPlugs will be automatically picked up by the annotation processor if they're in a @file:Autowired
file or annotated with @Autowired
.
This also means that they're eligable for dependency injection:
@file:Autowired
val leaveDepencies = module {
Single { Database() }
}
fun onMemberLeave(database: Database) = on<MemberLeaveEvent> {
database.removeMember(guildId, user.id)
}