discord.js icon indicating copy to clipboard operation
discord.js copied to clipboard

Added `setNames` & `setDescriptions` to (/) builders & context menu builder

Open Juknum opened this issue 2 years ago • 6 comments

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)

Juknum avatar Aug 18 '22 12:08 Juknum

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)

vercel[bot] avatar Aug 18 '22 12:08 vercel[bot]

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);

imranbarbhuiya avatar Aug 18 '22 12:08 imranbarbhuiya

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.

Juknum avatar Aug 18 '22 12:08 Juknum

That seems silly. Calling it a “wall of code”, even more so.

iCrawl avatar Aug 18 '22 13:08 iCrawl

This goes completely against the structure of builders, which have a set method per field, so I'm not too keen on it 😓

vladfrangu avatar Aug 21 '22 20:08 vladfrangu

AH F, I wasn't aware it would make this

Juknum avatar Sep 13 '22 22:09 Juknum

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.

kyranet avatar Oct 09 '22 21:10 kyranet