Add ability to set a flag description. #99

Merged
Soheab merged 5 commits from flags_option_description into 2.0 2021-10-16 12:27:02 +00:00
2 changed files with 22 additions and 4 deletions
Showing only changes of commit 7b5465c3b8 - Show all commits

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])