/Kotlin-JDA-Base

A JDA Starter Project in Kotlin with a few features.

Primary LanguageKotlinMIT LicenseMIT

Kotlin JDA Base

A JDA Starter Project in Kotlin with a few features.

Important Classes / Packages

How to use

Example

without command options (Ping.kt)

package me.monmcgt.code.commands.impl

import me.monmcgt.code.commands.CommandAbstract
import me.monmcgt.code.commands.CommandInfo
import me.monmcgt.code.commands.RegisterCommand

@RegisterCommand
@CommandInfo(name = "ping", description = "responds with pong")
class Ping : CommandAbstract() {
    override fun onSlashCommandInteraction() {
        sendEmphemralMessage("Pong!")
    }
}


without command options (UserAvatar.kt)

package me.monmcgt.code.commands.impl

import me.monmcgt.code.commands.CommandAbstract
import me.monmcgt.code.commands.CommandInfo
import me.monmcgt.code.commands.RegisterCommand

@RegisterCommand
@CommandInfo(name = "useravatar", description = "Get the avatar of a user")
class UserAvatar : CommandAbstract() {
    override fun onSlashCommandInteraction() {
        val member = event.member
        if (member == null) {
            sendEmphemralMessage("Something went wrong, please try again later")
            return
        }
        sendEmphemralMessage(member.user.effectiveAvatarUrl)
    }
}


with command options (YourName.kt)

package me.monmcgt.code.commands.impl

import me.monmcgt.code.commands.CommandAbstract
import me.monmcgt.code.commands.CommandInfo
import me.monmcgt.code.commands.RegisterCommand
import net.dv8tion.jda.api.interactions.commands.OptionType
import net.dv8tion.jda.api.interactions.commands.build.OptionData

@RegisterCommand
@CommandInfo(name = "yourname", description = "Returns your name")
class YourName : CommandAbstract() {
    override val optionDataArray: Array<OptionData>
        get() = arrayOf(OptionData(OptionType.STRING, "name", "Your name", true))

    override fun onSlashCommandInteraction() {
        event.getOption("name")?.let {
            sendEmphemralMessage("Your name is ${it.asString}")
        }
    }
}

Library

Inspiration