Merge branch '2.0' of https://github.com/iDevision/enhanced-discord.py into flags_option_description

This commit is contained in:
Soheab 2021-10-13 20:49:33 +02:00
commit 7b5465c3b8

View File

@ -136,6 +136,14 @@ application_option_type_lookup = {
discord.Role: 8,
float: 10,
}
application_option_channel_types = {
discord.VoiceChannel: [2],
discord.TextChannel: [0, 5, 6],
discord.CategoryChannel: [4],
discord.Thread: [10, 11, 12],
discord.StageChannel: [13],
}
if TYPE_CHECKING:
P = ParamSpec("P")
@ -1275,12 +1283,19 @@ class Command(_BaseCommand, Generic[CogT, P, T]):
for python_type, discord_type in application_option_type_lookup.items():
if issubclass(annotation, python_type):
option["type"] = discord_type
# Set channel types
if discord_type == 7:
option["channel_types"] = application_option_channel_types[annotation]
break
elif origin is Union:
if annotation in {Union[discord.Member, discord.Role], Union[MemberConverter, RoleConverter]}:
option["type"] = 9
elif all([arg in application_option_channel_types for arg in annotation.__args__]):
option["type"] = 7
option["channel_types"] = [discord_value for arg in annotation.__args__ for discord_value in application_option_channel_types[arg]]
elif origin is Literal:
literal_values = annotation.__args__
python_type = type(literal_values[0])