DiscordKM
A Kotlin Multiplatform Discord API Wrapper
Packages:
- DiscordKM (core)
- DiscordKM-Lavalink
- DiscordKM-Http-Interactions
Discord: Click here
Wiki: Click here
Warning: This project is in Alpha and can change without notice
Introduction
You can create a client easily by just using buildClient:
val client = buildClient("TOKEN") {
intents = mutableSetOf(
Intent.GUILD_MEMBERS,
Intent.GUILD_PRESENCES,
Intent.GUILD_WEBHOOKS,
Intent.GUILD_MESSAGE_TYPING,
Intent.DIRECT_MESSAGE_TYPING,
Intent.GUILDS
)
logging {
level = Logger.Level.WARN
}
reconnectDelay = 10.seconds
enabledCache -= CacheFlag.VOICE_STATES
}
client.on<MessageCreateEvent> {
println("Received message: ${message.content}")
}
client.on<ReadyEvent> {
client.commands.createChatInputCommand {
name = "test"
description = "This is a chat input command!"
options {
string(name = "option1", description = "This is a string option", required = true) {
choice("choice1", "choice1")
}
user("option2", "This is a user option", required = true)
}
}
}
client.on<SlashCommandEvent>(predicate = { it.commandName == "test" }) {
interaction.reply("String Option: ${options["option1"].string}. User Name: ${options["option2"].user.name}")
}
client.login()
JVM-Only
If you want to easily add event listeners without having to use the Kotlin DSL you can use the following:
client.importCommands("io.github.jan.bot.commands", subPackages = true, mapOf(
"someValue" to 1.0
) )
@CommandExecutor(name = "test", subCommand = "subCommand")
fun SlashCommandEvent.testCommand(@Inject("someValue") value: Double) {
interaction.reply("injected value: $value")
}
client.importEvents("io.github.jan.bot.events", subPackages = true, mapOf(
"node" to lavalinkNode
))
@EventListener
fun MessageCreateEvent.play(@Inject("node") lavalinkNode: LavalinkNode) {
}