Skip to content

Commit

Permalink
Use channel classes instead of their names
Browse files Browse the repository at this point in the history
  • Loading branch information
Dorukyum committed Jul 2, 2022
1 parent 33a0a25 commit b3137a7
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions discord/commands/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
from typing import Any, Dict, List, Literal, Optional, Union
from enum import Enum

from ..abc import GuildChannel
from ..channel import TextChannel, VoiceChannel, StageChannel, CategoryChannel, Thread
from ..enums import ChannelType, SlashCommandOptionType, Enum as DiscordEnum

__all__ = (
Expand All @@ -35,12 +37,12 @@
"option",
)

channel_type_map = {
"TextChannel": ChannelType.text,
"VoiceChannel": ChannelType.voice,
"StageChannel": ChannelType.stage_voice,
"CategoryChannel": ChannelType.category,
"Thread": ChannelType.public_thread,
CHANNEL_TYPE_MAP = {
TextChannel: ChannelType.text,
VoiceChannel: ChannelType.voice,
StageChannel: ChannelType.stage_voice,
CategoryChannel: ChannelType.category,
Thread: ChannelType.public_thread,
}


Expand All @@ -61,10 +63,6 @@ def __init__(self, thread_type: Literal["public", "private", "news"]):
}
self._type = type_map[thread_type]

@property
def __name__(self):
return "ThreadOption"


class Option:
"""Represents a selectable option for a slash command.
Expand Down Expand Up @@ -165,13 +163,13 @@ def __init__(self, input_type: Any = str, /, description: Optional[str] = None,
else:
input_type = (input_type,)
for i in input_type:
if i.__name__ == "GuildChannel":
if isinstance(i, type) and issubclass(i, GuildChannel):
continue
if isinstance(i, ThreadOption):
self.channel_types.append(i._type)
continue

channel_type = channel_type_map[i.__name__]
channel_type = CHANNEL_TYPE_MAP[i]
self.channel_types.append(channel_type)
input_type = _type
self.input_type = input_type
Expand Down

0 comments on commit b3137a7

Please sign in to comment.