Browse Source

Fixing localizations

* Fixed typo in `SlashCommandOptionBuilder.WithDescriptionLocalizations`
* Fixed typo in `SlashCommandOptionBuilder.AddNameLocalization`
* Changed `Build` method of both `ApplicationCommandOptionProperties` and `SlashCommandProperties` to not set the `NameLocalizations` and `DescriptionLocalizations` if null in the builder. Was causing an error in the setter.
pull/2457/head
Proddy GitHub 2 years ago
parent
commit
f41e9fee95
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 7 deletions
  1. +13
    -7
      src/Discord.Net.Core/Entities/Interactions/SlashCommands/SlashCommandBuilder.cs

+ 13
- 7
src/Discord.Net.Core/Entities/Interactions/SlashCommands/SlashCommandBuilder.cs View File

@@ -107,11 +107,13 @@ namespace Discord
Name = Name,
Description = Description,
IsDefaultPermission = IsDefaultPermission,
NameLocalizations = _nameLocalizations,
DescriptionLocalizations = _descriptionLocalizations,
IsDMEnabled = IsDMEnabled,
DefaultMemberPermissions = DefaultMemberPermissions ?? Optional<GuildPermission>.Unspecified
};
if (_nameLocalizations is not null)
props.NameLocalizations = _nameLocalizations;
if (_descriptionLocalizations is not null)
props.DescriptionLocalizations = _descriptionLocalizations;

if (Options != null && Options.Any())
{
@@ -538,7 +540,7 @@ namespace Discord
if (isStrType && MaxLength is not null && MaxLength < 1)
throw new InvalidOperationException("MaxLength cannot be smaller than 1.");

return new ApplicationCommandOptionProperties
var props = new ApplicationCommandOptionProperties
{
Name = Name,
Description = Description,
@@ -553,11 +555,15 @@ namespace Discord
ChannelTypes = ChannelTypes,
MinValue = MinValue,
MaxValue = MaxValue,
NameLocalizations = _nameLocalizations,
DescriptionLocalizations = _descriptionLocalizations,
MinLength = MinLength,
MaxLength = MaxLength,
};
if (_nameLocalizations is not null)
props.NameLocalizations = _nameLocalizations;
if (_descriptionLocalizations is not null)
props.DescriptionLocalizations = _descriptionLocalizations,
return props
}

/// <summary>
@@ -907,7 +913,7 @@ namespace Discord
if (descriptionLocalizations is null)
throw new ArgumentNullException(nameof(descriptionLocalizations));

foreach (var (locale, description) in _descriptionLocalizations)
foreach (var (locale, description) in descriptionLocalizations)
{
if(!Regex.IsMatch(locale, @"^\w{2}(?:-\w{2})?$"))
throw new ArgumentException($"Invalid locale: {locale}", nameof(locale));
@@ -933,7 +939,7 @@ namespace Discord

EnsureValidCommandOptionName(name);

_descriptionLocalizations ??= new();
_nameLocalizations ??= new();
_nameLocalizations.Add(locale, name);

return this;


Loading…
Cancel
Save