Skip to content

Commit 4179b3b

Browse files
NeloBlivionpre-commit-ci[bot]Lulalabyplun1331BobDotCom
authored
fix: Document Option.channel_types and properly support further channel 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 <[email protected]> Signed-off-by: UK <[email protected]> * Specify more appropriate type Signed-off-by: UK <[email protected]> --------- Signed-off-by: UK <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Lala Sabathil <[email protected]> Co-authored-by: plun1331 <[email protected]> Co-authored-by: BobDotCom <[email protected]>
1 parent 9da7cf9 commit 4179b3b

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

discord/commands/options.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,15 @@
2929
from typing import TYPE_CHECKING, Literal, Optional, Type, Union
3030

3131
from ..abc import GuildChannel, Mentionable
32-
from ..channel import CategoryChannel, StageChannel, TextChannel, Thread, VoiceChannel
32+
from ..channel import (
33+
CategoryChannel,
34+
DMChannel,
35+
ForumChannel,
36+
StageChannel,
37+
TextChannel,
38+
Thread,
39+
VoiceChannel,
40+
)
3341
from ..enums import ChannelType
3442
from ..enums import Enum as DiscordEnum
3543
from ..enums import SlashCommandOptionType
@@ -73,6 +81,8 @@
7381
StageChannel: ChannelType.stage_voice,
7482
CategoryChannel: ChannelType.category,
7583
Thread: ChannelType.public_thread,
84+
ForumChannel: ChannelType.forum,
85+
DMChannel: ChannelType.private,
7686
}
7787

7888

@@ -138,6 +148,10 @@ class Option:
138148
.. note::
139149
140150
Does not validate the input value against the autocomplete results.
151+
channel_types: list[:class:`discord.ChannelType`] | None
152+
A list of channel types that can be selected in this option.
153+
Only applies to Options with an :attr:`input_type` of :class:`discord.SlashCommandOptionType.channel`.
154+
If this argument is used, :attr:`input_type` will be ignored.
141155
name_localizations: Optional[Dict[:class:`str`, :class:`str`]]
142156
The name localizations for this option. The values of this should be ``"locale": "name"``.
143157
See `here <https://discord.com/developers/docs/reference#locales>`_ for a list of valid locales.
@@ -224,11 +238,12 @@ def __init__(
224238
self._raw_type = input_type.__args__ # type: ignore # Union.__args__
225239
else:
226240
self._raw_type = (input_type,)
227-
self.channel_types = [
228-
CHANNEL_TYPE_MAP[t]
229-
for t in self._raw_type
230-
if t is not GuildChannel
231-
]
241+
if not self.channel_types:
242+
self.channel_types = [
243+
CHANNEL_TYPE_MAP[t]
244+
for t in self._raw_type
245+
if t is not GuildChannel
246+
]
232247
self.required: bool = (
233248
kwargs.pop("required", True) if "default" not in kwargs else False
234249
)

discord/enums.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,8 @@ def from_datatype(cls, datatype):
787787
"CategoryChannel",
788788
"ThreadOption",
789789
"Thread",
790+
"ForumChannel",
791+
"DMChannel",
790792
]:
791793
return cls.channel
792794
if datatype.__name__ == "Role":

0 commit comments

Comments
 (0)