What is a Piece?

I often read this term but dont really understand it
Solution:
A "piece" is literally a "piece" of your code. Every Sapphire class (commands, preconditions, arguments, listeners, etc) extend the Piece class. Pieces have some properties that are therefore available on all of those classes.
Jump to solution
48 Replies
Solution
Favna
Favna2y ago
A "piece" is literally a "piece" of your code. Every Sapphire class (commands, preconditions, arguments, listeners, etc) extend the Piece class. Pieces have some properties that are therefore available on all of those classes.
Favna
Favna2y ago
Historically it's also a hold over from where Sapphire originated from. Sapphire spawned from Klasa (https://github.com/dirigeants/klasa/) which itself spawned from Komada (https://github.com/UnseenFaith/komada), and Komada is literally the Croatian word for "pieces"
chillihero
chillihero2y ago
is this apply options the same thing as in the super constructor?
chillihero
chillihero2y ago
those are properties of a piece correct?
Favna
Favna2y ago
no because the top one has subcommands and the bottom one enabled: true but if those differences wouldnt be there, yes @ApplyOptions creates a constructor and .. Applies.. Options..
chillihero
chillihero2y ago
do I need to set the values in both or is it enough if I declared them in one oh interesting
Favna
Favna2y ago
in fact you cannot use a normal constructor when using @ApplyOptions it will be overriden
chillihero
chillihero2y ago
this is a new area for me
Favna
Favna2y ago
I mean that's moreso a thing of decorators than of pieces in general
chillihero
chillihero2y ago
is there some documentation on the different properties that we can set there?
Favna
Favna2y ago
You're using VSCode. You can just use intellisense. Should be Ctrl + Space or you can just ctrl+click on the Options part of Subcommand.Options
chillihero
chillihero2y ago
jup but the things itself are not really described for example the difference between description and detaileddescription\
Favna
Favna2y ago
well we have a website
Favna
Favna2y ago
anyway as for those in particular neither is natively read by Sapphire but you can use either when you want to write a help command that said if you use slash commands then you only really need description if you use message commands and write a help command you can use detailedDescription to stuff detailed information in there such as usage, examples, etc detailedDescription is an interface (forgot the name) on which you can define required properties with module augmentation
chillihero
chillihero2y ago
whats fullcategory & flags? ah and how is the name set? because I never set that anywhere and it still registers the correct Name
Favna
Favna2y ago
so you can get like
detailedDescription: {
usage: '...',
examples: ['...', '...']
}
detailedDescription: {
usage: '...',
examples: ['...', '...']
}
etc
ararou!
ararou!2y ago
@Hyperfire well i guess this was your issue :joythink:
Hyper
Hyper2y ago
I just extended command Smh
Favna
Favna2y ago
fullCategory, category and all such related are set based on the folder it is in. For example if the structure is
commands/category/subcategory/command.ts
commands/category/subcategory/command.ts
then the fullCategory is ['category', 'subcategory'] You normally don't set the property manually through options as it is resolved automatically from the path as shown here. But if you want to overwrite this automatic resolution, then you set it.
ararou!
ararou!2y ago
keyword: was
Favna
Favna2y ago
if it's just for that usage then I strongly recommend using detailedDescription. It's far less complex.
Hyper
Hyper2y ago
Shut It's for more than that
Favna
Favna2y ago
fair
Hyper
Hyper2y ago
I have a hidden flag for hiding from help command and stuff And examples And usage
ararou!
ararou!2y ago
.
Favna
Favna2y ago
Favna
Favna2y ago
I mean you can also put hidden in there you can put literally anything in there
Hyper
Hyper2y ago
Yeah
Favna
Favna2y ago
much easier than extending the command class
Hyper
Hyper2y ago
Idk it was also just a good opportunity to get a better understanding of TS and how extending stuff works
Favna
Favna2y ago
extending classes isn't a TS thing, it's base JS* but I get what you mean I guess
ararou!
ararou!2y ago
i did the same and thought of removing the extended class but never got around to
Favna
Favna2y ago
declare module '@sapphire/framework' {
export interface DetailedDescriptionCommand {
usage: string;
examples: string[];
hidden: boolean
}
}
declare module '@sapphire/framework' {
export interface DetailedDescriptionCommand {
usage: string;
examples: string[];
hidden: boolean
}
}
should be this. Then when you write detailedDescription in your options it will expect those 3 properties to be defined. urgh should probably add this to the guide too but I always find it so hard where to put it
chillihero
chillihero2y ago
writing goood docs is a superpower tbh
ararou!
ararou!2y ago
i think your best option would to rewrite how it's done imo
Favna
Favna2y ago
huh
ararou!
ararou!2y ago
like needing to add .catch(() => null); to args
chillihero
chillihero2y ago
could you also explain how the name is set automatically & what flag does?
ararou!
ararou!2y ago
:shrug:
Favna
Favna2y ago
what why would you need that
ararou!
ararou!2y ago
args.pick('string') does not return null if we need to do if (!string)
Favna
Favna2y ago
args.pickResult
ararou!
ararou!2y ago
no thank
Favna
Favna2y ago
use slash commands then better pog
ararou!
ararou!2y ago
fair
Favna
Favna2y ago
name is the file name, or whatever you set and https://www.sapphirejs.dev/docs/Guide/arguments/using-flags
Sapphire Framework
Using flags | Sapphire
So far we have covered arguments, which are positional - i.e., the order of the arguments matters and they are parsed in
chillihero
chillihero2y ago
super helpful, thank you favna
Want results from more Discord servers?
Add your server