Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Document Option.channel_types and properly support further channel types #1883

Merged
merged 11 commits into from Jan 27, 2023
27 changes: 21 additions & 6 deletions discord/commands/options.py
Expand Up @@ -29,7 +29,15 @@
from typing import TYPE_CHECKING, Literal, Optional, Type, Union

from ..abc import GuildChannel, Mentionable
from ..channel import CategoryChannel, StageChannel, TextChannel, Thread, VoiceChannel
from ..channel import (
CategoryChannel,
DMChannel,
ForumChannel,
StageChannel,
TextChannel,
Thread,
VoiceChannel,
)
from ..enums import ChannelType
from ..enums import Enum as DiscordEnum
from ..enums import SlashCommandOptionType
Expand Down Expand Up @@ -73,6 +81,8 @@
StageChannel: ChannelType.stage_voice,
CategoryChannel: ChannelType.category,
Thread: ChannelType.public_thread,
ForumChannel: ChannelType.forum,
DMChannel: ChannelType.private,
}


Expand Down Expand Up @@ -138,6 +148,10 @@ class Option:
.. note::

Does not validate the input value against the autocomplete results.
channel_types: Optional[List[:class:`discord.ChannelType`]]
NeloBlivion marked this conversation as resolved.
Show resolved Hide resolved
A list of channel types that can be selected in this option.
Only applies to Options with an :attr:`input_type` of :class:`discord.abc.GuildChannel`.
NeloBlivion marked this conversation as resolved.
Show resolved Hide resolved
If this argument is used, :attr:`input_type` will be ignored.
name_localizations: Optional[Dict[:class:`str`, :class:`str`]]
The name localizations for this option. The values of this should be ``"locale": "name"``.
See `here <https://discord.com/developers/docs/reference#locales>`_ for a list of valid locales.
Expand Down Expand Up @@ -224,11 +238,12 @@ def __init__(
self._raw_type = input_type.__args__ # type: ignore # Union.__args__
else:
self._raw_type = (input_type,)
self.channel_types = [
CHANNEL_TYPE_MAP[t]
for t in self._raw_type
if t is not GuildChannel
]
if not self.channel_types:
self.channel_types = [
CHANNEL_TYPE_MAP[t]
for t in self._raw_type
if t is not GuildChannel
]
self.required: bool = (
kwargs.pop("required", True) if "default" not in kwargs else False
)
Expand Down
2 changes: 2 additions & 0 deletions discord/enums.py
Expand Up @@ -787,6 +787,8 @@ def from_datatype(cls, datatype):
"CategoryChannel",
"ThreadOption",
"Thread",
"ForumChannel",
"DMChannel",
]:
return cls.channel
if datatype.__name__ == "Role":
Expand Down