|
26 | 26 |
|
27 | 27 | from ..enums import ChannelType, SlashCommandOptionType
|
28 | 28 |
|
| 29 | + |
29 | 30 | __all__ = (
|
30 | 31 | "ThreadOption",
|
31 | 32 | "Option",
|
@@ -70,20 +71,30 @@ def __init__(self, input_type: Any, /, description: str = None, **kwargs) -> Non
|
70 | 71 | self.converter = input_type
|
71 | 72 | input_type = SlashCommandOptionType.string
|
72 | 73 | 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 |
87 | 98 | self.input_type = input_type
|
88 | 99 | self.required: bool = (
|
89 | 100 | kwargs.pop("required", True) if "default" not in kwargs else False
|
|
0 commit comments