discord.js
discord.js copied to clipboard
Added `setNames` & `setDescriptions` to (/) builders & context menu builder
I have created this PR to avoid the wall of code you have when you want to localize a command when registering it using builders.
Please describe the changes this PR makes and why it should be merged:
This PR add methods that combine the basic setName()
& setNameLocalizations()
, setDescription()
& setDescriptionLocalizations()
together.
Allowing you to make this:
new SlashCommandBuilder()
.setNames('en-US', NamesLocalizationMap)
.setDescriptions('en-US', DescriptionLocalizationMap)
.setDMPermission(false)
.addChannelOption((channel) =>
channel
.setNames('en-US', ChannelOptionNamesLocalizationMap)
.setDescriptions('en-US', ChannelOptionDescriptionLocalizationMap)
.setRequired(true)
);
Instead of the actual wall of code (which becomes huge with more parameters)
new SlashCommandBuilder()
.setName(NamesLocalizationMap['en-US'])
.setDescription(DescriptionLocalizationMap['en-US'])
.setNameLocalizations(NamesLocalizationMap)
.setDescriptionLocalizations(DescriptionLocalizationMap)
.setDMPermission(false)
.addChannelOption((channel) =>
channel
.setName(ChannelOptionNamesLocalizationMap['en-US'])
.setDescription(ChannelOptionDescriptionLocalizationMap['en-US'])
.setNameLocalizations(ChannelOptionNamesLocalizationMap)
.setDescriptionLocalizations(ChannelOptionDescriptionLocalizationMap)
.setRequired(true)
);
Status and versioning classification:
- I know how to update typings and have done so, or typings don't need updating
- This PR changes the library's interface (methods or parameters added)
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Ignored Deployment
Name | Status | Preview | Updated |
---|---|---|---|
discord-js | ⬜️ Ignored (Inspect) | Aug 18, 2022 at 0:17AM (UTC) |
I'm not sure what u mean by to avoid the wall of code
.
Before
builder.setName(name).setNameLocalizations(localizedNames);
After
builder.setNames(locale, localizedNames);
I'm not sure what u mean by
to avoid the wall of code
.
I have added an example in the PR description, having to declare both basic name/description & localized ones is redundant.
That seems silly. Calling it a “wall of code”, even more so.
This goes completely against the structure of builders, which have a set method per field, so I'm not too keen on it 😓
AH F, I wasn't aware it would make this
Hi, thank you for your contribution, but I'm sorry we will have to close this PR.
We talked internally about this feature, and the concensus was to not accept this PR due to the reason @vladfrangu mentioned previously in this PR. There's a design we strive for in builders, and we want to stick with it.
I personally believe that adding extra, convenience methods, would open a can of worms, which can potentially cause higher development cost. And the code savings from those methods are also very minimal, saving just 2 lines of code in codebases like yours.