Skip to content

Commit

Permalink
fix: Document Option.channel_types and properly support further chann…
Browse files Browse the repository at this point in the history
…el types (#1883)

* Add channel_types documentation for discord.Option

* fix doc note

* Support forum and private channels(?)

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Clarification in docs

* typo

* Use new annotation syntax

Co-authored-by: BobDotCom <71356958+BobDotCom@users.noreply.github.com>
Signed-off-by: UK <41271523+NeloBlivion@users.noreply.github.com>

* Specify more appropriate type

Signed-off-by: UK <41271523+NeloBlivion@users.noreply.github.com>

---------

Signed-off-by: UK <41271523+NeloBlivion@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Lala Sabathil <lala@pycord.dev>
Co-authored-by: plun1331 <49261529+plun1331@users.noreply.github.com>
Co-authored-by: BobDotCom <71356958+BobDotCom@users.noreply.github.com>
  • Loading branch information
5 people authored Jan 27, 2023
1 parent 9da7cf9 commit 4179b3b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
27 changes: 21 additions & 6 deletions discord/commands/options.py
Original file line number Diff line number Diff line change
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: list[:class:`discord.ChannelType`] | None
A list of channel types that can be selected in this option.
Only applies to Options with an :attr:`input_type` of :class:`discord.SlashCommandOptionType.channel`.
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
Original file line number Diff line number Diff line change
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

0 comments on commit 4179b3b

Please sign in to comment.