K
Kord•2y ago
Shaun

How do I unregister commands to reregister them with updates?

How do I unregister commands to reregister them with updates?
97 Replies
g
g•2y ago
get the command object from Discord and call .delete() but you don't have to do that if you're just updating a command you can just create it again
Shaun
ShaunOP•2y ago
It's not updating
kord.createGlobalChatInputCommand("item", "Estimates a price for a given item") {
attachment("image", "A screenshot of the popup when you hover the item") {
required = true
}
}
kord.createGlobalChatInputCommand("item", "Estimates a price for a given item") {
attachment("image", "A screenshot of the popup when you hover the item") {
required = true
}
}
I'm running this and it doesn't update
g
g•2y ago
did you wait an hour before checking that? global commands can take a while to be evicted from the client's cache
Shaun
ShaunOP•2y ago
No, ah I remember that's a thing... IIRC you can do it on each guild and its instant right?
g
g•2y ago
guild ones are usually instant yeah
Shaun
ShaunOP•2y ago
How can I get access to all guilds we're in?
g
g•2y ago
kord.guilds current shard only I think you seem like you're writing a framework, are you sure you wouldn't prefer to use an existing one?
Shaun
ShaunOP•2y ago
do I call that after .login or anywhere in particular? And wdym a framework? I'm just copying the docs
g
g•2y ago
ah, I see kord provides the protocol implementation, frameworks provide the abstractions on top for actually writing the bot and you'd have to call it after your guilds have been received you might be better off reacting to the guild creation event
Shaun
ShaunOP•2y ago
kord is just a wrapper of the discord API, and there are other higher level frameworks built on kord that would make my life easier?
g
g•2y ago
pretty much yeah
Shaun
ShaunOP•2y ago
Would you recommend any?
g
g•2y ago
I maintain kordex so I'd rec that, but there's a comparison table here https://docs.kordex.dev/framework-comparison.html
Shaun
ShaunOP•2y ago
Is it well documented?
g
g•2y ago
well, that's the documentation site it's not finished but a good chunk of the important stuff is done
Shaun
ShaunOP•2y ago
What's this? never seen this in my life gradle/libs.versions.toml
g
g•2y ago
that's a version catalog
Shaun
ShaunOP•2y ago
Optional?
g
g•2y ago
https://docs.gradle.org/current/userguide/platforms.html#sub:conventional-dependencies-toml don't ask me why this is the url it's optional yeah, it's just one of a few ways of specifying dependencies man those gradle doc urls suck lmao
Shaun
ShaunOP•2y ago
No description
g
g•2y ago
is that a linter?
Shaun
ShaunOP•2y ago
Just IDEA
g
g•2y ago
oh yeah, mine complains as well odd, that's new
Shaun
ShaunOP•2y ago
It doesn't like the newlines Wants it all on same line
g
g•2y ago
hm, odd, was fine when I wrote that no biggie tho, just remove the newlines there's a template here if you prefer https://github.com/kord-extensions/template
Shaun
ShaunOP•2y ago
lmao this library is kotlin af I love it
g
g•2y ago
lmao, well that was the idea, idiomatic api
Shaun
ShaunOP•2y ago
Okay so I followed the guide to register a command and I still don't see it How do I add to to every guild in this framework
g
g•2y ago
you want to add global commands to every guild?
Shaun
ShaunOP•2y ago
Just for testing purposes rn, yes
g
g•2y ago
or, what, you want all commands to be guild commands?
Shaun
ShaunOP•2y ago
It's just so I can iterate on the command fast
g
g•2y ago
if you're testing, I'd recommend registering all global commands to a single guild
Shaun
ShaunOP•2y ago
Yea sure
g
g•2y ago
you can set a default guild in the application commands builder https://docs.kordex.dev/config-commands.html#application-command-functions you could do like
Shaun
ShaunOP•2y ago
And it will automatically register commands to that guild?
g
g•2y ago
yep
applicationCommands {
defaultGuild(envOrNull("TEST_GUILD_ID"))
}
applicationCommands {
defaultGuild(envOrNull("TEST_GUILD_ID"))
}
for example
Shaun
ShaunOP•2y ago
No description
g
g•2y ago
or just hardcode it, whatever, you know what you're doing ah yeah I've seen this, one sec when it came up on the kordex server, it turned out to be a discord caching problem solved by kicking and re-adding the bot just checked not really sure why it happens, I wasn't able to reproduce it
Shaun
ShaunOP•2y ago
Yea that solved it, thanks
g
g•2y ago
no worries
Shaun
ShaunOP•2y ago
are there docs around retrieving attachments?
g
g•2y ago
in what context? like, receiving an attachment as a slash command argument?
Shaun
ShaunOP•2y ago
Yes
g
g•2y ago
yeah, just add an argument for it have you made an Arguments subtype yet? for your command's arguments one of these https://docs.kordex.dev/commands.html#arguments-classes ah jeez, it autoformatted out my indents again writerside is pain sometimes
Shaun
ShaunOP•2y ago
inner class PredictPriceArgs : Arguments() {
val image by attachment {
name = "image"
description = "A screenshot of the item popup"
}
}
inner class PredictPriceArgs : Arguments() {
val image by attachment {
name = "image"
description = "A screenshot of the item popup"
}
}
I have this
g
g•2y ago
that looks correct
Shaun
ShaunOP•2y ago
So I'm guessing somewhere in my action I can grab the image
g
g•2y ago
yeah, arguments.image
Shaun
ShaunOP•2y ago
😮
g
g•2y ago
lmao you can tell I beat the type system into submission with that one
Shaun
ShaunOP•2y ago
When people try and argue java is a better language I'm going to show them this framework Can I do my processing in action {} ?
g
g•2y ago
you probably could do something similar in java you'd just need a lot more boilerplate yeah, it's a coroutine, do what you need you can always use a dispatcher if it's really a problem, but it should be fine
Shaun
ShaunOP•2y ago
Does it get uploaded to a URL or do I have an access to the bytes?
g
g•2y ago
it has a url property
Shaun
ShaunOP•2y ago
Gotcha
g
g•2y ago
I don't recall if we provide a quick download let me see
Shaun
ShaunOP•2y ago
Can I group arguments or should I create a separate command with separate arguments?
g
g•2y ago
yes, .download and .downloadToFile or .downloadToFolder
Shaun
ShaunOP•2y ago
E.g (IMAGE or (NAME and RARITY and ATTRIBUTES))
g
g•2y ago
you can use command groups if you feel like it'd make the UX better each subcommand would need its own arguments class though it really depends on what you think would be more intuitive for your users there's subcommands and command groups, https://docs.kordex.dev/slash-commands.html#subcommands
Shaun
ShaunOP•2y ago
I want either
/price image_attachment:attachment
/price name:string rarity:string attributes:List<String>
/price image_attachment:attachment
/price name:string rarity:string attributes:List<String>
g
g•2y ago
discord doesn't really support that
Shaun
ShaunOP•2y ago
I'll do it as separate commands then
g
g•2y ago
you could have /price image <attachment> and /price data ... tho so you'd define your root command as normal, don't provide an arguments class or an action block, and then use the subCommand builders inside it
Shaun
ShaunOP•2y ago
Just curious, why do we have the set the name here? Couldn't you grab it from the delegate?
No description
g
g•2y ago
in theory yes, but KordEx has built-in support for i18n, so you could eg provide a translation key for the name can't really have dots in a property name
Shaun
ShaunOP•2y ago
Ahhh yes makes sense
g
g•2y ago
publicSlashCommand {
name = "price"
description = "..."

publicSubCommand {
name = "image"
// ...
}

// ...
}
publicSlashCommand {
name = "price"
description = "..."

publicSubCommand {
name = "image"
// ...
}

// ...
}
what I meant earlier took me a minute haha the type of the parent command doesn't matter if you're using subcommands it feels a bit odd but it didn't make sense to have a separate type for groups imo if you define checks on a parent command, they'll be inherited by subcommands as well
Shaun
ShaunOP•2y ago
I feel like I'm taking the piss now, can you have "map" parameters somehow?
g
g•2y ago
key-value parameters? not really, no
Shaun
ShaunOP•2y ago
Fuck
g
g•2y ago
container-based parameters don't make sense given how discord's done slash commands you could theoretically support your own delimiter and split on it with a string argument
Shaun
ShaunOP•2y ago
Yea, would that work with autocomplete though It's pretty important from a UX perspective autocomplete is there
g
g•2y ago
you could make it work
Shaun
ShaunOP•2y ago
I saw you can say its autocomplete prefixes
g
g•2y ago
you can provide an autocomplete callback that provides suggestions it's up to you what those suggestions are you have access to the provided value, of course
Shaun
ShaunOP•2y ago
Oh really , is suggestStringCollection something you've created for convience?
g
g•2y ago
yes https://docs.kordex.dev/converters.html#settings-all-autocomplete the suggestion functions filter the collection based on the provided value and filtering strategy and then provide the matching values as separate suggestions
Shaun
ShaunOP•2y ago
Oohh I have an idea actually
g
g•2y ago
you can have up to 25 suggestions
Shaun
ShaunOP•2y ago
Can we do dynamic parameters? That would be mcuh better
g
g•2y ago
what do you mean by that?
Shaun
ShaunOP•2y ago
Bare with
/price name:"Longsword" Damage:20 BonusTrueDamage:1
/price name:"Boots" MoveSpeed:20 BonusTrueDamage:1
/price name:"Longsword" Damage:20 BonusTrueDamage:1
/price name:"Boots" MoveSpeed:20 BonusTrueDamage:1
Essentially, based on the name parameter, other arguments become available, you would not be suggested MoveSpeed on Longsword, in this case.
g
g•2y ago
command registration requires you to specify all arguments and their types to Discord in advance unfortunately
Shaun
ShaunOP•2y ago
And there are no conditional args
g
g•2y ago
no but by overriding a property in the arguments class, you can get at earlier argument values in the autocomplete builder for later arguments so you could, I suppose, have a bunch of optional arguments and then use autocomplete to tell the user the argument isn't applicable seems janky though you can only have 25 arguments as well
Shaun
ShaunOP•2y ago
I could register each item as sub command?
g
g•2y ago
you could do that, but again, 25 subcommands
Shaun
ShaunOP•2y ago
😭
g
g•2y ago
discord's command system isn't really made for this haha I suppose you could have separate commands for modifying each attribute but that makes things more cumbersome honestly maybe the kind of thing a web interface would be better for but that module isn't done yet /lh
Shaun
ShaunOP•2y ago
Can I have a repeated argument
g
g•2y ago
there are no collection arguments for slash commands
Shaun
ShaunOP•2y ago
That's surprising
g
g•2y ago
you'd have to duplicate it with a different name each time that's discord for ya you could probably collapse that into a list using a by lazy property I guess, still cumbersome though probably worth mentioning that there's nothing particularly special about the properties on your arguments class, you can add whatever you need there the converter functions (used to define arguments) add each argument to a list in the background, that's how they get filled haha I'm gonna be shutting down my PC now (it's late) but your IDE and the docs site both have searches if you need them tho writerside's search is.. not amazing. but it'll get you there.
Shaun
ShaunOP•2y ago
Thanks for your help I'll see what I can do
g
g•2y ago
No worries, gl with it There's a separate KordEx server linked in the docs if you need that as well

Did you find this page helpful?