K
Kord6mo ago
Ray

Easy way to register commands

Is there an annotation or other way to directly define and associate a command with a function? For example, taken from the wiki:
kord.createGuildChatInputCommand(
Snowflake(botInfo.serverId),
"sum",
"A slash command that sums two numbers"
) {
integer("first_number", "The first operand") {
required = true
}
integer("second_number", "The second operand") {
required = true
}
}

kord.on<GuildChatInputCommandInteractionCreateEvent> {
val response = interaction.deferPublicResponse()
val command = interaction.command
logger.debug { "interaction command: ${command.rootName}" }
val first = command.integers["first_number"]!! // it's required so it's never null
val second = command.integers["second_number"]!!
response.respond { content = "$first + $second = ${first + second}" }
}
kord.createGuildChatInputCommand(
Snowflake(botInfo.serverId),
"sum",
"A slash command that sums two numbers"
) {
integer("first_number", "The first operand") {
required = true
}
integer("second_number", "The second operand") {
required = true
}
}

kord.on<GuildChatInputCommandInteractionCreateEvent> {
val response = interaction.deferPublicResponse()
val command = interaction.command
logger.debug { "interaction command: ${command.rootName}" }
val first = command.integers["first_number"]!! // it's required so it's never null
val second = command.integers["second_number"]!!
response.respond { content = "$first + $second = ${first + second}" }
}
Could be something like:
@GuildChatInputCommandInteraction(name="sum")
fun inputCommandSum(
builder: ChatInputCreateBuilder,
interaction: GuildChatInputCommandInteraction
) {}
@GuildChatInputCommandInteraction(name="sum")
fun inputCommandSum(
builder: ChatInputCreateBuilder,
interaction: GuildChatInputCommandInteraction
) {}
16 Replies
gdude
gdude6mo ago
What you want is a framework
gdude
gdude6mo ago
I'm only aware of two active frameworks built on top of Kord right now, so I've compared them on this page disclaimer, I develop Kord Extensions, so like, I'm biased but I've had Jake look over the table for accuracy
Ray
RayOP6mo ago
Ooo thank you, I'll take a look
gdude
gdude6mo ago
yw neither of them are annotation-based afaik
Ray
RayOP6mo ago
As a side note, what's the "Conversations API"?
gdude
gdude6mo ago
The idea behind a conversational API is that it'd provide an abstraction over a set of steps, basically so you'd define a flow for the user to go through for example, idk, a series of questions
Ray
RayOP6mo ago
That sounds nice
gdude
gdude6mo ago
there's an issue open for it on kordex, but I believe discordkt actually has something for this
Ray
RayOP6mo ago
Is there a "hybrid" command that encapsulates both regular prefixed commands and slash commands? Or should I just not bother with prefixed ones? Sorry for all the questions, I'm rewriting my bots from Python to Kotlin
gdude
gdude6mo ago
KordEx doesn't have something for that - there was a third-party library for it, but it hasn't been kept up to date I'm not sure about DKT you can use the same arguments type for both command types on KordEx, and you can extract the command actions into functions, but I don't think there's a base type with all the functions you'd need
Ray
RayOP6mo ago
I was thinking about that, but was hoping there was something already. Thanks, I'll go through the docs for both
gdude
gdude6mo ago
👍 docs are still WIP but you can see that by the emoji in the sidebar
Ray
RayOP6mo ago
I'm going with Kord Extensions, the docs look way better
gdude
gdude6mo ago
alright, thanks for your support haha if you need help with KordEx I'd recommend checking out the Answer Overflow page, and then asking in the support forum on the KordEx server so the question and answer can be indexed keeping knowledge locked on discord is awful
Ray
RayOP6mo ago
Thanks, I was just about to ask for a link
Want results from more Discord servers?
Add your server