You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 16, 2023. It is now read-only.
BartArys edited this page Sep 16, 2020
·
1 revision
Most sufficiently complex Discord bots will end up interacting with more than just MessageCreateEvent events.
For this, kordx.commands.kord introduces the EventPlug.
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() }
}
funonMemberLeave(database:Database) = on<MemberLeaveEvent> {
database.removeMember(guildId, user.id)
}