Add proper literal support
This commit is contained in:
parent
8a779ef595
commit
623fcc0ac0
@ -1231,14 +1231,19 @@ class Command(_BaseCommand, Generic[CogT, P, T]):
|
|||||||
option["type"] = discord_type
|
option["type"] = discord_type
|
||||||
break
|
break
|
||||||
|
|
||||||
elif origin is Literal and len(origin.__args__) <= 25: # type: ignore
|
elif origin is Literal:
|
||||||
option["choices"] = [{
|
literal_values = annotation.__args__
|
||||||
"name": literal_value,
|
python_type = type(literal_values[0])
|
||||||
"value": literal_value
|
if (all(type(value) == python_type for value in literal_values)
|
||||||
} for literal_value in origin.__args__] # type: ignore
|
and python_type in application_option_type_lookup.keys()):
|
||||||
else:
|
|
||||||
option["type"] = 3 # STRING
|
|
||||||
|
|
||||||
|
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)
|
payload["options"].append(option)
|
||||||
|
|
||||||
# Now we have all options, make sure required is before optional.
|
# Now we have all options, make sure required is before optional.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user