Skip to content

Commit

Permalink
Update EnumConverter and ApplicationCommandOption to register localiz…
Browse files Browse the repository at this point in the history
…ations (#2651)
  • Loading branch information
TrustNoOneElse committed Apr 2, 2023
1 parent a8ae1e9 commit 75ae488
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Discord.WebSocket;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
Expand All @@ -22,6 +23,7 @@ public override void Write(ApplicationCommandOptionProperties properties, IParam
{
var names = Enum.GetNames(typeof(T));
var members = names.SelectMany(x => typeof(T).GetMember(x)).Where(x => !x.IsDefined(typeof(HideAttribute), true));
var localizationManager = parameterInfo.Command.Module.CommandService.LocalizationManager;

if (members.Count() <= 25)
{
Expand All @@ -33,7 +35,8 @@ public override void Write(ApplicationCommandOptionProperties properties, IParam
choices.Add(new ApplicationCommandOptionChoiceProperties
{
Name = displayValue,
Value = member.Name
Value = member.Name,
NameLocalizations = localizationManager?.GetAllNames(parameterInfo.GetChoicePath(new ParameterChoice(displayValue.ToLower(), member.Name)), LocalizationTarget.Choice) ?? ImmutableDictionary<string, string>.Empty
});
}
properties.Choices = choices;
Expand Down
3 changes: 2 additions & 1 deletion src/Discord.Net.Rest/API/Common/ApplicationCommandOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ public ApplicationCommandOption(ApplicationCommandOptionProperties option)
Choices = option.Choices?.Select(x => new ApplicationCommandOptionChoice
{
Name = x.Name,
Value = x.Value
Value = x.Value,
NameLocalizations = x.NameLocalizations?.ToDictionary() ?? Optional<Dictionary<string, string>>.Unspecified,
}).ToArray() ?? Optional<ApplicationCommandOptionChoice[]>.Unspecified;

Options = option.Options?.Select(x => new ApplicationCommandOption(x)).ToArray() ?? Optional<ApplicationCommandOption[]>.Unspecified;
Expand Down

0 comments on commit 75ae488

Please sign in to comment.