Read property from custom Command Options
Hey folks,
I have a custom command options object, that contains a property called
shortDesc
.
I want to read a property from the options, inside the registerApplicationCommands
method, so that I can not have to provide this value (Get a random trivia question
) twice.
How do I read shortDesc
? this.shortDesc
didn't work the same as this.name
did - I assume because name
exists on the default CommandOptions
object, but it's having trouble parsing the Options here as IDrpgCommandOptions
?
Solution:Jump to solution
First of all, the reason it works in your help command is because you're using
command.options
, likewise if you use this.options.shortDesc
it'll also be there.
Secondly, categories are built into sapphire so whatever you're setting in the constructor there is pretty pointless. That dates back to a very old by now version of Sapphire where categories weren't integrated
Thirdly, Sapphire Command class has a detailedDescription
option which can be an object of whatever you want and is set automatically so you do not even need custom properties for this at all. Just use module augmentation to modify the interface for detailedDescription
then use ...10 Replies
can we see
DrpgCommand
?
if you have shortDesc
there then it must workCOMMAND_OPTIONS
is just IDrpgCommandOptions
with some defaults set
it's not part of the object, it's part of the Optionsadd
public readonly shortDesc: string;
in your class
basically you need to add all of the extra options you addeddoes that change the way I add/apply those options?
no
that makes it a member of your class
Until now your extra options were useless
I've been using them okay in a help command
I think actually... another approach to the answer exists in this code above... 🫣
Thanks for the guidance though - I'll try this out tomorrow 🙂
Solution
First of all, the reason it works in your help command is because you're using
command.options
, likewise if you use this.options.shortDesc
it'll also be there.
Secondly, categories are built into sapphire so whatever you're setting in the constructor there is pretty pointless. That dates back to a very old by now version of Sapphire where categories weren't integrated
Thirdly, Sapphire Command class has a detailedDescription
option which can be an object of whatever you want and is set automatically so you do not even need custom properties for this at all. Just use module augmentation to modify the interface for detailedDescription
then use
and reference it with this.detailedDescription.shortDesc
Fourthly, you don't need a help command when going slash commands only because every command and every option already gets a description and if your commands/options are so convoluted that you cannot describe them in 100 characters then you should revise the command as a whole.Thanks Favna - honestly I'm not sure what I was doing with the constructor there - it existed in whatever sample project/source material I referenced, possibly Skyra? My understanding is that it was trying to use the folder structure to automatically build the categories, if they hadn't been provided
Also, am not going slash commands only - supporting both
how new is
detailedDescription
? I've been out of touch the last couple of months and hadn't come across it before
That dates back to a very old by now version of Sapphire where categories weren't integratedThat'd be right - the code there is well over 12 months old some time around August/September 2021
skyra hasnt had that in the constructor for ages and ages
since like v1.x
Like I said - it's been there for ages and ages
before there were even docs of any kind