From afc272588f235f9a14c2f6163f3ba5e1360b6d4b Mon Sep 17 00:00:00 2001 From: UK <41271523+NeloBlivion@users.noreply.github.com> Date: Tue, 17 Jan 2023 21:34:38 +0000 Subject: [PATCH 1/8] Add channel_types documentation for discord.Option --- discord/commands/options.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/discord/commands/options.py b/discord/commands/options.py index 936eb34d9c..b1a5394589 100644 --- a/discord/commands/options.py +++ b/discord/commands/options.py @@ -134,6 +134,9 @@ class Option: The autocomplete handler for the option. Accepts an iterable of :class:`str`, a callable (sync or async) that takes a single argument of :class:`AutocompleteContext`, or a coroutine. Must resolve to an iterable of :class:`str`. + channel_types: Optional[List[:class:`discord.ChannelType`]] + 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`. .. note:: From 91ad03e8da3f2887d186e3e56725d225471851dd Mon Sep 17 00:00:00 2001 From: UK <41271523+NeloBlivion@users.noreply.github.com> Date: Tue, 17 Jan 2023 22:10:37 +0000 Subject: [PATCH 2/8] fix doc note --- discord/commands/options.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/discord/commands/options.py b/discord/commands/options.py index b1a5394589..25787a810b 100644 --- a/discord/commands/options.py +++ b/discord/commands/options.py @@ -134,13 +134,13 @@ class Option: The autocomplete handler for the option. Accepts an iterable of :class:`str`, a callable (sync or async) that takes a single argument of :class:`AutocompleteContext`, or a coroutine. Must resolve to an iterable of :class:`str`. - channel_types: Optional[List[:class:`discord.ChannelType`]] - 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`. .. note:: Does not validate the input value against the autocomplete results. + channel_types: Optional[List[:class:`discord.ChannelType`]] + 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`. name_localizations: Optional[Dict[:class:`str`, :class:`str`]] The name localizations for this option. The values of this should be ``"locale": "name"``. See `here `_ for a list of valid locales. From 935ee5df2d31964debcf0d68723e2afea3213fda Mon Sep 17 00:00:00 2001 From: UK <41271523+NeloBlivion@users.noreply.github.com> Date: Wed, 18 Jan 2023 00:10:08 +0000 Subject: [PATCH 3/8] Support forum and private channels(?) --- discord/commands/options.py | 15 +++++++++------ discord/enums.py | 2 ++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/discord/commands/options.py b/discord/commands/options.py index 25787a810b..c3d38fe2f8 100644 --- a/discord/commands/options.py +++ b/discord/commands/options.py @@ -29,7 +29,7 @@ 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, StageChannel, TextChannel, Thread, VoiceChannel, ForumChannel, DMChannel from ..enums import ChannelType from ..enums import Enum as DiscordEnum from ..enums import SlashCommandOptionType @@ -73,6 +73,8 @@ StageChannel: ChannelType.stage_voice, CategoryChannel: ChannelType.category, Thread: ChannelType.public_thread, + ForumChannel: ChannelType.forum, + DMChannel: ChannelType.private, } @@ -227,11 +229,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 ) diff --git a/discord/enums.py b/discord/enums.py index 746a9c86c0..ca5ac6df2c 100644 --- a/discord/enums.py +++ b/discord/enums.py @@ -787,6 +787,8 @@ def from_datatype(cls, datatype): "CategoryChannel", "ThreadOption", "Thread", + "ForumChannel", + "DMChannel" ]: return cls.channel if datatype.__name__ == "Role": From 6c1f0e771019b03e08a4a075c09f8b52fa374313 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 18 Jan 2023 00:12:45 +0000 Subject: [PATCH 4/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- discord/commands/options.py | 10 +++++++++- discord/enums.py | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/discord/commands/options.py b/discord/commands/options.py index c3d38fe2f8..ef3bdff502 100644 --- a/discord/commands/options.py +++ b/discord/commands/options.py @@ -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, ForumChannel, DMChannel +from ..channel import ( + CategoryChannel, + DMChannel, + ForumChannel, + StageChannel, + TextChannel, + Thread, + VoiceChannel, +) from ..enums import ChannelType from ..enums import Enum as DiscordEnum from ..enums import SlashCommandOptionType diff --git a/discord/enums.py b/discord/enums.py index ca5ac6df2c..72fdad9102 100644 --- a/discord/enums.py +++ b/discord/enums.py @@ -788,7 +788,7 @@ def from_datatype(cls, datatype): "ThreadOption", "Thread", "ForumChannel", - "DMChannel" + "DMChannel", ]: return cls.channel if datatype.__name__ == "Role": From d624746f9ca71edec80136a6c06a91166a77dfc3 Mon Sep 17 00:00:00 2001 From: UK <41271523+NeloBlivion@users.noreply.github.com> Date: Wed, 18 Jan 2023 00:17:01 +0000 Subject: [PATCH 5/8] Clarification in docs --- discord/commands/options.py | 1 + 1 file changed, 1 insertion(+) diff --git a/discord/commands/options.py b/discord/commands/options.py index ef3bdff502..8054e0ae60 100644 --- a/discord/commands/options.py +++ b/discord/commands/options.py @@ -151,6 +151,7 @@ class Option: channel_types: Optional[List[:class:`discord.ChannelType`]] 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`. + If this argument is uses, :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 `_ for a list of valid locales. From 727d0bd333665dec3e45fee225f6b8ea8c2cb08d Mon Sep 17 00:00:00 2001 From: UK <41271523+NeloBlivion@users.noreply.github.com> Date: Wed, 18 Jan 2023 00:19:28 +0000 Subject: [PATCH 6/8] typo --- discord/commands/options.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/commands/options.py b/discord/commands/options.py index 8054e0ae60..b12e1cfc3c 100644 --- a/discord/commands/options.py +++ b/discord/commands/options.py @@ -151,7 +151,7 @@ class Option: channel_types: Optional[List[:class:`discord.ChannelType`]] 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`. - If this argument is uses, :attr:`input_type` will be ignored. + 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 `_ for a list of valid locales. From c456b6b23d916ab7122076923af9785a1ec994a7 Mon Sep 17 00:00:00 2001 From: UK <41271523+NeloBlivion@users.noreply.github.com> Date: Fri, 27 Jan 2023 14:32:43 +0000 Subject: [PATCH 7/8] Use new annotation syntax Co-authored-by: BobDotCom <71356958+BobDotCom@users.noreply.github.com> Signed-off-by: UK <41271523+NeloBlivion@users.noreply.github.com> --- discord/commands/options.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/commands/options.py b/discord/commands/options.py index b12e1cfc3c..8d22e2bdc5 100644 --- a/discord/commands/options.py +++ b/discord/commands/options.py @@ -148,7 +148,7 @@ class Option: .. note:: Does not validate the input value against the autocomplete results. - channel_types: Optional[List[:class:`discord.ChannelType`]] + 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.abc.GuildChannel`. If this argument is used, :attr:`input_type` will be ignored. From 731216f29babfad80608b657e8034fdd84ebf050 Mon Sep 17 00:00:00 2001 From: UK <41271523+NeloBlivion@users.noreply.github.com> Date: Fri, 27 Jan 2023 19:08:30 +0000 Subject: [PATCH 8/8] Specify more appropriate type Signed-off-by: UK <41271523+NeloBlivion@users.noreply.github.com> --- discord/commands/options.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/commands/options.py b/discord/commands/options.py index 8d22e2bdc5..d6c04faf72 100644 --- a/discord/commands/options.py +++ b/discord/commands/options.py @@ -150,7 +150,7 @@ class Option: 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.abc.GuildChannel`. + 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"``.