Skip to content

v3.1.0 | Checkboxes, radio groups and checkbox groups

Latest

Choose a tag to compare

@freya022 freya022 released this 29 Mar 19:50
· 17 commits to 3.X since this release
af3d5da

JDA

Updated to JDA 6.4.0 and added support for checkboxes, radio groups and checkbox groups.


Checkboxes, checkbox groups and radio groups (#253)

This adds support for reading values in modal handlers, and Kotlin extensions + DSL builders for the new modals components.

Values of those new components can now be read as:

  • Checkbox -> Boolean
  • CheckboxGroup -> List<String>, String for single values (can be null)
  • RadioGroup -> String (can be null)
Example command
private const val MODAL_NAME = "SlashModal: modal"
private const val CHECKBOX_ID = "checkbox-id"
private const val RADIO_GROUP_ID = "radio_group-id"
private const val CHECKBOX_GROUP_ID = "checkbox_group-id"

@Command
class SlashModal(private val modals: Modals) {
    @JDASlashCommand(name = "modal", description = "Test new modal features!")
    fun onSlashModal(event: GuildSlashEvent) {
        val modal = modals.create("Modal") {
            label("I like checking boxes") {
                child = Checkbox(CHECKBOX_ID, isDefault = true)
            }

            label("Which Discord client do you use?") {
                child = RadioGroup(RADIO_GROUP_ID) {
                    option("Discord (Stable)", "stable", "The vanilla option", default = true)
                    option("Discord PTB", "ptb", "A peek into the future")
                    option("Discord Canary", "canary", "Living on the edge")
                }
            }

            label("Which modal components do you use?") {
                child = CheckboxGroup(CHECKBOX_GROUP_ID) {
                    option("Text Inputs", "textinputs")
                    option("Select Menus", "selectmenus")
                    option("File Uploads", "fileuploads")
                    option("Checkbox groups", "checkboxgroups", default = true)
                }
            }

            bindTo(MODAL_NAME)
        }

        event.replyModal(modal).queue()
    }

    @ModalHandler(MODAL_NAME)
    fun onModal(
        event: ModalEvent,
        @ModalInput(CHECKBOX_ID) doTheyLikeCheckingBoxes: Boolean,
        @ModalInput(RADIO_GROUP_ID) client: String,
        @ModalInput(CHECKBOX_GROUP_ID) features: List<String>,
    ) {
        event.reply("""
            Do you like checking boxes? $doTheyLikeCheckingBoxes
            On what client? $client
            Using what features? $features
        """.trimIndent())
            .setEphemeral(true)
            .queue()
    }
}

JDA PR: discord-jda/JDA#3010


New feature

jda-ktx

  • Added RestActionReasonContext and withRestActionReasonContext
    • Coroutine support for JDA's ThreadLocalReason

Don't hesitate to check out the examples and the wiki.

Full Changelog: v3.0.0...v3.1.0


Installation

As a reminder, the minimum Java version supported is Java 17.

Kotlin Gradle

repositories {
    mavenCentral()
}

dependencies {
    implementation("io.github.freya022:BotCommands:3.1.0")
}

Maven

<dependency>
    <groupId>io.github.freya022</groupId>
    <artifactId>BotCommands</artifactId>
    <version>3.1.0</version>
</dependency>