K
Kord2w ago
sbot50

Is there a good way to register all commands at once?

I tried literally everything to get getKord().createGlobalApplicationCommands {} to function But unless i wanna create a massive file with every command in there seperately, it wont work. ATM all the registering code is inside its own class files. but as soon as i try doing input("a","b") {} (for example) inside a loop it wont work, even if said loop only runs once. Now my previous method of just spamming dc with register requests for each command on startup... works... but i would rather not have to do that, since sooner or later itll ratelimit me. To be clear, yes doing doing:
getKord().createGlobalApplicationCommands {
input("a","b") {}
input("c","d") {}
input("e","f") {}
}
getKord().createGlobalApplicationCommands {
input("a","b") {}
input("c","d") {}
input("e","f") {}
}
works, but I would rather not have to do that (im using normal kord, not kord extensions)
6 Replies
matytyma
matytyma2w ago
ATM all the registering code is inside its own class files. but as soon as i try doing input("a","b") {} (for example) inside a loop it wont work, even if said loop only runs once.
Could you share the not-working code?
sbot50
sbot50OP2w ago
sure In the init functions of my Commands class I have this code:
val cmds = getKord().createGlobalApplicationCommands {
for (command in commands) {
(command as Command).register(this)
}
}
val cmds = getKord().createGlobalApplicationCommands {
for (command in commands) {
(command as Command).register(this)
}
}
To be clear however, this doesnt work either
val cmds = getKord().createGlobalApplicationCommands {
for (command in commands) {
input("a", "b") {}
break
}
}
val cmds = getKord().createGlobalApplicationCommands {
for (command in commands) {
input("a", "b") {}
break
}
}
the register function in commands literally just does this, unless overridden:
open fun register(builder: MultiApplicationCommandBuilder) {
return builder.input(cmdName, cmdDescription)
}
open fun register(builder: MultiApplicationCommandBuilder) {
return builder.input(cmdName, cmdDescription)
}
If i do this however:
val cmds = getKord().createGlobalApplicationCommands {
input("a", "b") {}
for (command in commands) {
break
}
}
val cmds = getKord().createGlobalApplicationCommands {
input("a", "b") {}
for (command in commands) {
break
}
}
it obviously works fine, I also tried setting this to a variable if that somehow would matter, but no luck I should mention that this:
val cmds = getKord().createGlobalApplicationCommands {
Ping().register(this)
}
val cmds = getKord().createGlobalApplicationCommands {
Ping().register(this)
}
works fine (aka getting a command and doing .register without going through a loop, I dislike this solution tho because then i already have all commands in a list so i can reference them later. So based on this my assumption is that its a scoping issue
matytyma
matytyma2w ago
val cmds = getKord().createGlobalApplicationCommands {
for (command in commands) {
input("a", "b") {}
break
}
}
val cmds = getKord().createGlobalApplicationCommands {
for (command in commands) {
input("a", "b") {}
break
}
}
Why do you have a break here? And how is commands defined?
sbot50
sbot50OP2w ago
because i thought maybe the issue was that it registered the same cmd every loop
private val commands = listOf<Command>(
// General
Ping(),
WelcomeMsg(),

// Information
Define(),
Urbandefine(),

// Utility
Eval(),
Wolframalpha(),

// Moderation
Purge(),

// Fun
Coinflip(),
Diceroll(),
Magic8Ball(),
Walrus()
)
private val commands = listOf<Command>(
// General
Ping(),
WelcomeMsg(),

// Information
Define(),
Urbandefine(),

// Utility
Eval(),
Wolframalpha(),

// Moderation
Purge(),

// Fun
Coinflip(),
Diceroll(),
Magic8Ball(),
Walrus()
)
this is commands it just makes an object of every command for future use
sbot50
sbot50OP2w ago
oh bruh, ig i found my issue
No description
sbot50
sbot50OP2w ago
give me 1 sec, if thats actually the issue ill close the post, but im pretty dissapointed in myself not spotting that Ok, im less of an idiot than i thought, still dumb tho. Appearently my commands list was name-shadowed because the createglobalapplicationcommandsbuilder or whatever long name its called internally also has a commands list, so it was using that instead of mine. thx for the help btw

Did you find this page helpful?