A simple command
, button
, select menu
and modal
manager for Kord, a Kotlin Discord
API
wrapper.
This project is no longer being maintained. Short-lived, resting in peace, awaiting its sequel.
Planned features:
- Slash command manager
- Button manager
- Select menu manager
- Modal manager
- Automatic help menu
Made with love by @azuyamat
Kormmand is available on Jitpack. Here is how to add it to your project.
Note: Replace
Tag
with the latest version of Kormmand.
Maven
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<dependency>
<groupId>com.github.Azuyamat</groupId>
<artifactId>Kormmand</artifactId>
<version>Tag</version>
</dependency>
Gradle
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
dependencies {
implementation 'com.github.Azuyamat:Kormmand:Tag'
}
Kotlin Gradle
repositories {
mavenCentral()
maven("https://jitpack.io")
}
dependencies {
implementation("com.github.Azuyamat:Kormmand:Tag")
}
Commands
To create a command, start by initializing a class that extends the Command
interface.
Don't forget to include @CommandClass
and @InteractionClass
annotations. Otherwise, the command won't be registered.
@InteractionClass
@CommandClass
class HelpCommand : Command {
override val name: String = "help"
override val description: String = "Show the help menu."
override suspend fun execute(event: GuildChatInputCommandInteractionCreateEvent) {
event.interaction.respondPublic {
content = "This is a test" }
}
}
For commands to function, they must first be registered. To do this, you must create a CommandManager
and register
the commands via their package name.
Multiple command
val commandManager = CommandManager(kord).apply {
registerInteractions("commands")
}
Registering guild commands only requires that you add the guild id as a parameter.
val commandManager = CommandManager(kord).apply {
registerInteractions("commands", "GUILDID")
}
To add permission requirements to a command, you must add the permission
property to the command.
@InteractionClass
@CommandClass
class HelpCommand : Command {
override val name: String = "help"
override val description: String = "Show the help menu."
override val permission: Permission = Permission.Administrator
override suspend fun execute(event: GuildChatInputCommandInteractionCreateEvent) {
event.interaction.respondPublic {
content = "You are an admin!" }
}
}
To add subcommands to a command, you must add the builder
property to the command.
@InteractionClass
@CommandClass
class HelpCommand : Command {
override val name: String = "help"
override val description: String = "Show the help menu."
override val builder: GlobalChatInputCreateBuilder.() -> Unit = {
subCommand("info", "Get info about a user."){
user("user", "The user to get info about.")
}
}
override suspend fun execute(event: GuildChatInputCommandInteractionCreateEvent) {
val interaction = event.interaction
val c = interaction.command
val subCommandName = when (c) {
is RootCommand -> null
is GroupCommand -> c.name
is SubCommand -> c.name
}
if (subCommandName == "info") {
interaction.respondPublic {
content = "This is a test"
}
}
}
}
Buttons
To create a button, start by initializing a class that extends the Button
interface.
Don't forget to add the @InteractionClass
annotation. Otherwise, the button won't be registered.
@InteractionClass
class HelpButton : Button {
override val id: String = "help"
override val name: String = "help" // Not required for buttons
override val description: String = "Show the help menu." // Not required for buttons
override suspend fun execute(event: ButtonInteractionCreateEvent) {
event.interaction.respondPublic {
content = "This is a test" }
}
}
For a button to function, it must be registered by the bot at runtime. To do this, you must create a ButtonManager
and register the button.
Multiple buttons
val buttonManager = ButtonManager(kord).apply {
registerInteractions("buttons")
}
Guild-specific buttons
Don't know why you'd do this but you can register buttons that will only run in specific guilds
val buttonManager = ButtonManager(kord).apply {
registerInteractions("buttons", "GUILDID")
}
To add permission requirements to a button, you must add the permission
property to the button.
@InteractionClass
class HelpButton : Button {
override val name: String = "help" // Not required for buttons
override val description: String = "Show the help menu." // Not required for buttons
override val permission: Permission = Permission.Administrator
override suspend fun execute(event: ButtonInteractionCreateEvent) {
event.interaction.respondPublic {
content = "You are an admin!" }
}
}
Modals
To create a modal, start by initializing a class that extends the Modal
interface.
Don't forget to add the @InteractionClass
annotation. Otherwise, the modal won't be registered.
@InteractionClass
class HelpModal : Modal {
override val id: String = "modal"
override val name: String = "modal" // Not required for modals
override val description: String = "Show the help menu." // Not required for modals
override suspend fun execute(event: ModalSubmitInteractionCreateEvent) {
event.interaction.respondPublic {
content = "This is a test" }
}
}
For a modal to function, it must be registered by the bot at runtime. To do this, you must create a ModalManager
and register the modal's package.
Multiple modals
val modalManager = ModalManager(kord).apply {
registerInteractions("modals")
}
Guild-specific modals
Don't know why you'd do this but, you can register guild-specific modals
val modalManager = ModalManager(kord).apply {
registerInteractions("modals", "GUILDID")
}
To add permission requirements to a command, you must add the permission
property to the modal.
@InteractionClass
class HelpModal : Modal {
override val name: String = "help" // Not required for modals
override val description: String = "Show the help menu." // Not required for modals
override val permission: Permission = Permission.Administrator
override suspend fun execute(event: ModalSubmitInteractionCreateEvent) {
event.interaction.respondPublic {
content = "You are an admin!" }
}
}
Select Menus
To create a select menu, start by initializing a class that extends the SelectMenu
interface.
Don't forget to add the @InteractionClass
annotation. Otherwise, the select menu won't be registered.
@InteractionClass
class HelpMenu : SelectMenu {
override val id: String = "jeff"
override val name: String = "jeff" // Not required for select menus
override val description: String = "Show the help menu." // Not required for select menus
override suspend fun execute(event: SelectMenuInteractionCreateEvent) {
event.interaction.respondPublic {
content = "This is a test" }
}
}
For a select menu to function, it must be registered by the bot at runtime. To do this, you must create a
SelectMenuManager
and register the select menu's package.
Multiple select menus
val selectMenuManager = ModalManager(kord).apply {
registerInteractions("selectMenus")
}
Guild-specific select menus
Once again, don't know why you'd do this but you can register guild-specific select menus
val selectMenuManager = ModalManager(kord).apply {
registerInteractions("selectMenus", "GUILDID")
}
To add permission requirements to a command, you must add the permission
property to the select menu.
@InteractionClass
class HelpMenu : SelectMenu {
override val name: String = "help" // Not required for select menu
override val description: String = "Show the help menu." // Not required for select menu
override val permission: Permission = Permission.Administrator
override suspend fun execute(event: SelectMenuInteractionCreateEvent) {
event.interaction.respondPublic {
content = "You are an admin!" }
}
}
Note: Buttons, modals and select menus use the first part of the interaction id. This means you can split your interaction id by
//
and use the first part as the id while having the rest as interaction parameters.Example:
val task = interaction.modalId.split("//")[1]
Contributions are welcome! If you have any issues or feature requests, please open an issue or a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.