diff --git a/docs/guides/int_framework/samples/intro/groupattribute.cs b/docs/guides/int_framework/samples/intro/groupattribute.cs
index 86a492c31..99d6cd67b 100644
--- a/docs/guides/int_framework/samples/intro/groupattribute.cs
+++ b/docs/guides/int_framework/samples/intro/groupattribute.cs
@@ -1,16 +1,18 @@
[SlashCommand("blep", "Send a random adorable animal photo")]
-public async Task Blep([Choice("Dog", "dog"), Choice("Cat", "cat"), Choice("Penguin", "penguin")] string animal)
+public async Task Blep([Choice("Dog", "dog"), Choice("Cat", "cat"), Choice("Guinea pig", "GuineaPig")] string animal)
{
...
}
-// In most cases, you can use an enum to replace the seperate choice attributes in a command.
+// In most cases, you can use an enum to replace the separate choice attributes in a command.
public enum Animal
{
Cat,
Dog,
- Penguin
+ // You can also use the ChoiceDisplay attribute to change how they appear in the choice menu.
+ [ChoiceDisplay("Guinea pig")]
+ GuineaPig
}
[SlashCommand("blep", "Send a random adorable animal photo")]
diff --git a/samples/InteractionFramework/ExampleEnum.cs b/samples/InteractionFramework/ExampleEnum.cs
index 755f33d17..a70dd49a9 100644
--- a/samples/InteractionFramework/ExampleEnum.cs
+++ b/samples/InteractionFramework/ExampleEnum.cs
@@ -1,3 +1,11 @@
+using Discord.Interactions;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
namespace InteractionFramework
{
public enum ExampleEnum
@@ -5,6 +13,8 @@ namespace InteractionFramework
First,
Second,
Third,
- Fourth
+ Fourth,
+ [ChoiceDisplay("Twenty First")]
+ TwentyFirst
}
}
diff --git a/src/Discord.Net.Interactions/Attributes/EnumChoiceAttribute.cs b/src/Discord.Net.Interactions/Attributes/EnumChoiceAttribute.cs
new file mode 100644
index 000000000..c7f83b6cd
--- /dev/null
+++ b/src/Discord.Net.Interactions/Attributes/EnumChoiceAttribute.cs
@@ -0,0 +1,25 @@
+using System;
+
+namespace Discord.Interactions
+{
+ ///
+ /// Customize the displayed value of a slash command choice enum. Only works with the default enum type converter.
+ ///
+ [AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)]
+ public class ChoiceDisplayAttribute : Attribute
+ {
+ ///
+ /// Gets the name of the parameter.
+ ///
+ public string Name { get; } = null;
+
+ ///
+ /// Modify the default name and description values of a Slash Command parameter.
+ ///
+ /// Name of the parameter.
+ public ChoiceDisplayAttribute(string name)
+ {
+ Name = name;
+ }
+ }
+}
diff --git a/src/Discord.Net.Interactions/TypeConverters/EnumConverter.cs b/src/Discord.Net.Interactions/TypeConverters/EnumConverter.cs
index a06c70ec4..1406c6f1a 100644
--- a/src/Discord.Net.Interactions/TypeConverters/EnumConverter.cs
+++ b/src/Discord.Net.Interactions/TypeConverters/EnumConverter.cs
@@ -2,6 +2,7 @@ using Discord.WebSocket;
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Reflection;
using System.Threading.Tasks;
namespace Discord.Interactions
@@ -27,12 +28,14 @@ namespace Discord.Interactions
var choices = new List();
foreach (var member in members)
+ {
+ var displayValue = member.GetCustomAttribute()?.Name ?? member.Name;
choices.Add(new ApplicationCommandOptionChoiceProperties
{
- Name = member.Name,
+ Name = displayValue,
Value = member.Name
});
-
+ }
properties.Choices = choices;
}
}