Add support for channel_types in options
This commit is contained in:
parent
80775db1a4
commit
ac3187f62e
@ -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")
|
||||
@ -1266,12 +1274,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([issubclass(x, (discord.abc.GuildChannel, discord.abc.Messageable)) for x in annotation.__args__]):
|
||||
option["type"] = 7
|
||||
option["channel_types"] = [x for y in annotation.__args__ for x in application_option_channel_types[y]]
|
||||
|
||||
elif origin is Literal:
|
||||
literal_values = annotation.__args__
|
||||
python_type = type(literal_values[0])
|
||||
|
Loading…
x
Reference in New Issue
Block a user