From 623fcc0ac059bcf51daeb78a7c24e4a727a3c617 Mon Sep 17 00:00:00 2001 From: Gnome Date: Fri, 3 Sep 2021 20:18:15 +0100 Subject: [PATCH] Add proper literal support --- discord/ext/commands/core.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/discord/ext/commands/core.py b/discord/ext/commands/core.py index 6bca3f31..b23f8d16 100644 --- a/discord/ext/commands/core.py +++ b/discord/ext/commands/core.py @@ -1231,14 +1231,19 @@ class Command(_BaseCommand, Generic[CogT, P, T]): option["type"] = discord_type break - elif origin is Literal and len(origin.__args__) <= 25: # type: ignore - option["choices"] = [{ - "name": literal_value, - "value": literal_value - } for literal_value in origin.__args__] # type: ignore - else: - option["type"] = 3 # STRING + elif origin is Literal: + literal_values = annotation.__args__ + python_type = type(literal_values[0]) + if (all(type(value) == python_type for value in literal_values) + and python_type in application_option_type_lookup.keys()): + option["type"] = application_option_type_lookup[python_type] + option["choices"] = [{ + "name": literal_value, + "value": literal_value + } for literal_value in annotation.__args__] + + option.setdefault("type", 3) # STRING payload["options"].append(option) # Now we have all options, make sure required is before optional.