Add Channel types support #100

Merged
Chiggy-Playz merged 4 commits from ChannelTypes into 2.0 2021-10-13 16:34:13 +00:00

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")
@ -1265,12 +1273,19 @@ class Command(_BaseCommand, Generic[CogT, P, T]):
for python_type, discord_type in application_option_type_lookup.items():
Gnome-py commented 2021-10-13 15:47:27 +00:00 (Migrated from github.com)
Review

Please use descriptive variable names here

Please use descriptive variable names here
Gnome-py commented 2021-10-13 15:48:20 +00:00 (Migrated from github.com)
Review

If I am not mistaken, you can just check if all of the annotation args are in application_option_channel_types

If I am not mistaken, you can just check if all of the annotation args are in `application_option_channel_types`
Chiggy-Playz commented 2021-10-13 16:31:47 +00:00 (Migrated from github.com)
Review

Fixed in e84cef2

Fixed in e84cef2
Chiggy-Playz commented 2021-10-13 16:32:08 +00:00 (Migrated from github.com)
Review

Fixed in e84cef2

Fixed in e84cef2
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])