Skip to content

Getting Started

KCommands is a rather simple high-level Slash Command API in Kotlin for JDA.

Java Interopability

This library was not made with any Java abstractions, using the API in Java is not very great. Because this library was not made with Java interop in mind, it's recommended against using it with this library, and is why these docs will only have Kotlin examples.

Before getting started, you'll need to add "https://mvn.greemdev.net/repository/maven-releases" as a repository to your build tool of choice's build script, and add it as a dependency

Maven
<dependency>
    <groupId>net.greemdev</groupId>
    <artifactId>kcommands</artifactId>
    <version>VERSION</version>
</dependency>
Gradle Kotlin DSL
dependencies {
    implementation("net.greemdev:kcommands:VERSION")
}

To use the API, you'll need to create a class that can override the SlashCommand abstract class, initializing it with your command name and description of what it does as its parameters.

Example
    class SayCommand : SlashCommand("say", "Bot repeats what you tell it to.") {
        override fun handleSlashCommand(ctxt: SlashCommandContext) {}
    }

If your command has any options, preconditions, or buttons, you'll want to have a primary constructor body to configure the stuff in.

Example
    init {
        options {
            // note 'requiredString'. All option functions follow that format 
            // to prevent enum name repetition. If you wanted an optional role option, you'd use 'optionalRole'.
            requiredString("content", "What to say")
        }
    }

Now, if we combine the two examples, we get a valid (albeit non-functional) SlashCommand object (it was also usable without the options, and no primary constructor). In order to do something with the command, we'll want to add our code in handleSlashCommand.

Example
    override fun handleSlashCommand(ctx: SlashCommandContext) {
        event.reply(ctx.getOptionValue<String>("content"))
    }

There you have it! A functional Discord Slash Command made with this library.

In theory at least.