diff --git a/discord/ext/commands/core.py b/discord/ext/commands/core.py index 9650bd6f..42ef5ff9 100644 --- a/discord/ext/commands/core.py +++ b/discord/ext/commands/core.py @@ -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(): 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])