Skip to content

Commit b3137a7

Browse files
committed
Use channel classes instead of their names
1 parent 33a0a25 commit b3137a7

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

discord/commands/options.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
from typing import Any, Dict, List, Literal, Optional, Union
2727
from enum import Enum
2828

29+
from ..abc import GuildChannel
30+
from ..channel import TextChannel, VoiceChannel, StageChannel, CategoryChannel, Thread
2931
from ..enums import ChannelType, SlashCommandOptionType, Enum as DiscordEnum
3032

3133
__all__ = (
@@ -35,12 +37,12 @@
3537
"option",
3638
)
3739

38-
channel_type_map = {
39-
"TextChannel": ChannelType.text,
40-
"VoiceChannel": ChannelType.voice,
41-
"StageChannel": ChannelType.stage_voice,
42-
"CategoryChannel": ChannelType.category,
43-
"Thread": ChannelType.public_thread,
40+
CHANNEL_TYPE_MAP = {
41+
TextChannel: ChannelType.text,
42+
VoiceChannel: ChannelType.voice,
43+
StageChannel: ChannelType.stage_voice,
44+
CategoryChannel: ChannelType.category,
45+
Thread: ChannelType.public_thread,
4446
}
4547

4648

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

64-
@property
65-
def __name__(self):
66-
return "ThreadOption"
67-
6866

6967
class Option:
7068
"""Represents a selectable option for a slash command.
@@ -165,13 +163,13 @@ def __init__(self, input_type: Any = str, /, description: Optional[str] = None,
165163
else:
166164
input_type = (input_type,)
167165
for i in input_type:
168-
if i.__name__ == "GuildChannel":
166+
if isinstance(i, type) and issubclass(i, GuildChannel):
169167
continue
170168
if isinstance(i, ThreadOption):
171169
self.channel_types.append(i._type)
172170
continue
173171

174-
channel_type = channel_type_map[i.__name__]
172+
channel_type = CHANNEL_TYPE_MAP[i]
175173
self.channel_types.append(channel_type)
176174
input_type = _type
177175
self.input_type = input_type

0 commit comments

Comments
 (0)