Skip to content

Commit

Permalink
Fix slash converters
Browse files Browse the repository at this point in the history
  • Loading branch information
Ratery authored and Lulalaby committed Feb 8, 2022
1 parent 105a3cc commit 913f3bd
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions discord/commands/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

from ..enums import ChannelType, SlashCommandOptionType


__all__ = (
"ThreadOption",
"Option",
Expand Down Expand Up @@ -70,20 +71,30 @@ def __init__(self, input_type: Any, /, description: str = None, **kwargs) -> Non
self.converter = input_type
input_type = SlashCommandOptionType.string
else:
_type = SlashCommandOptionType.from_datatype(input_type)
if _type == SlashCommandOptionType.channel:
if not isinstance(input_type, tuple):
input_type = (input_type,)
for i in input_type:
if i.__name__ == "GuildChannel":
continue
if isinstance(i, ThreadOption):
self.channel_types.append(i._type)
continue

channel_type = channel_type_map[i.__name__]
self.channel_types.append(channel_type)
input_type = _type
try:
_type = SlashCommandOptionType.from_datatype(input_type)
except TypeError as exc:
from ..ext.commands.converter import CONVERTER_MAPPING

if input_type in CONVERTER_MAPPING:
self.converter = CONVERTER_MAPPING[input_type]
input_type = SlashCommandOptionType.string
else:
raise exc
else:
if _type == SlashCommandOptionType.channel:
if not isinstance(input_type, tuple):
input_type = (input_type,)
for i in input_type:
if i.__name__ == "GuildChannel":
continue
if isinstance(i, ThreadOption):
self.channel_types.append(i._type)
continue

channel_type = channel_type_map[i.__name__]
self.channel_types.append(channel_type)
input_type = _type
self.input_type = input_type
self.required: bool = (
kwargs.pop("required", True) if "default" not in kwargs else False
Expand Down

0 comments on commit 913f3bd

Please sign in to comment.