Ray
Ray
Explore posts from servers
KKord
Created by Ray on 6/9/2024 in #help
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
) {}
28 replies
KKord
Created by Ray on 6/8/2024 in #help
`Unresolved reference: int` when creating input command
I'm following the example in the very sparse wiki, but it doesn't seem to be valid anymore (it was last updated over 2 years ago). I get the error Unresolved reference: int, string seems to not show errors though. Any ideas on how to fix this? Or are there any more complex sample projects I could look at?
kord.createGuildChatInputCommand(
Snowflake(556525343595298817),
"sum",
"A slash command that sums two numbers"
) {
string("first_number", "The first operand") {
required = true
}
int("second_number", "The second operand") {
required = true
}
}
kord.createGuildChatInputCommand(
Snowflake(556525343595298817),
"sum",
"A slash command that sums two numbers"
) {
string("first_number", "The first operand") {
required = true
}
int("second_number", "The second operand") {
required = true
}
}
45 replies