K
Kord4mo ago
retlihe

Chat input command trailing lambda separation

I am attempting to write a function which creates chat input command (as a part of a slash command interface). There are two different methods Kord.createGuildChatInputCommand and Kord.createGlobalChatInputCommand. The command parameters are exactly the same. How can I separate the command parameters so I only have to write it once?
2 Replies
retlihe
retlihe4mo ago
I have made a solution
suspend fun register(bot: Bot, guildId: Snowflake?, builder: ChatInputCreateBuilder.() -> Unit) {
if (guildId == null) {
bot.kord.createGlobalChatInputCommand(name, description, builder)
} else {
bot.kord.createGuildChatInputCommand(guildId, name, description, builder)
}
}
suspend fun register(bot: Bot, guildId: Snowflake?, builder: ChatInputCreateBuilder.() -> Unit) {
if (guildId == null) {
bot.kord.createGlobalChatInputCommand(name, description, builder)
} else {
bot.kord.createGuildChatInputCommand(guildId, name, description, builder)
}
}
gdude
gdude4mo ago
Yep that's one way to do it, though if you're on the JVM, maybe you want to use a framework instead of duplicating work
Want results from more Discord servers?
Add your server