Skip to content

Commit 913f3bd

Browse files
RateryLulalaby
authored andcommitted
Fix slash converters
1 parent 105a3cc commit 913f3bd

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

discord/commands/options.py

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
from ..enums import ChannelType, SlashCommandOptionType
2828

29+
2930
__all__ = (
3031
"ThreadOption",
3132
"Option",
@@ -70,20 +71,30 @@ def __init__(self, input_type: Any, /, description: str = None, **kwargs) -> Non
7071
self.converter = input_type
7172
input_type = SlashCommandOptionType.string
7273
else:
73-
_type = SlashCommandOptionType.from_datatype(input_type)
74-
if _type == SlashCommandOptionType.channel:
75-
if not isinstance(input_type, tuple):
76-
input_type = (input_type,)
77-
for i in input_type:
78-
if i.__name__ == "GuildChannel":
79-
continue
80-
if isinstance(i, ThreadOption):
81-
self.channel_types.append(i._type)
82-
continue
83-
84-
channel_type = channel_type_map[i.__name__]
85-
self.channel_types.append(channel_type)
86-
input_type = _type
74+
try:
75+
_type = SlashCommandOptionType.from_datatype(input_type)
76+
except TypeError as exc:
77+
from ..ext.commands.converter import CONVERTER_MAPPING
78+
79+
if input_type in CONVERTER_MAPPING:
80+
self.converter = CONVERTER_MAPPING[input_type]
81+
input_type = SlashCommandOptionType.string
82+
else:
83+
raise exc
84+
else:
85+
if _type == SlashCommandOptionType.channel:
86+
if not isinstance(input_type, tuple):
87+
input_type = (input_type,)
88+
for i in input_type:
89+
if i.__name__ == "GuildChannel":
90+
continue
91+
if isinstance(i, ThreadOption):
92+
self.channel_types.append(i._type)
93+
continue
94+
95+
channel_type = channel_type_map[i.__name__]
96+
self.channel_types.append(channel_type)
97+
input_type = _type
8798
self.input_type = input_type
8899
self.required: bool = (
89100
kwargs.pop("required", True) if "default" not in kwargs else False

0 commit comments

Comments
 (0)