From 7500665725239d7cf8c5a2463f488348be91641e Mon Sep 17 00:00:00 2001 From: ToothyDev <55001472+ToothyDev@users.noreply.github.com> Date: Mon, 16 Nov 2026 19:37:08 +0100 Subject: [PATCH 1/4] fix: Make `User | Member` option types map to `SlashCommandOptionType.user` (#3425) * Make User | Member option unions work properly * Add changelog * Address change requests * Update CHANGELOG.md Co-authored-by: Paillat Signed-off-by: ToothyDev <55001472+ToothyDev@users.noreply.github.com> * Remove unnecessary extra check * chore: Update old `Optional[...]` syntax to use new `type | None` syntax (#3407) * Update old None-types to use correct syntax This will make None clickable in the docs and lead to the python docs * Documentation changes * Code changes * Fix up extra space * Apply change requests and fix docs * Apply change requests Co-authored-by: Michael <8661717+sgtlaggy@users.noreply.github.com> * Update new leftover Optionals use * Update old :data:None to use obj:None style Napoleon seems to internally use this style as well, so I'm choosing it over the existing :data: type --------- Co-authored-by: Michael <8661717+sgtlaggy@users.noreply.github.com> --------- Signed-off-by: ToothyDev <55001472+ToothyDev@users.noreply.github.com> Signed-off-by: Paillat Co-authored-by: Paillat Co-authored-by: Michael <8661717+sgtlaggy@users.noreply.github.com> --- CHANGELOG.md | 3 +++ discord/enums.py | 2 ++ 2 files changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 136776fd35..e2b278dad9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -77,6 +77,9 @@ These changes are available on the `master` branch, but have not yet been releas ([#3273](https://github.com/Pycord-Development/pycord/pull/3273)) - Fixed a race condition where `Bot.latency` could be reported incorrectly and grow indefinitely ([#3414](https://github.com/Pycord-Development/pycord/pull/3414)) +- Fixed the `input_type` of options typed as `Member | User` to be + `SlashCommandOptionType.user` instead of `SlashCommandOptionType.mentionable`. + ([#3425](https://github.com/Pycord-Development/pycord/pull/3425)) - Fixed a bug where audio reception would drop after prolonged silence in a voice channel. ([#3436](https://github.com/Pycord-Development/pycord/pull/3436)) diff --git a/discord/enums.py b/discord/enums.py index 5950ad463a..05c2d49e87 100755 --- a/discord/enums.py +++ b/discord/enums.py @@ -882,6 +882,8 @@ def from_datatype(cls, datatype): datatypes = [cls.from_datatype(op) for op in datatype] if all(x == cls.channel for x in datatypes): return cls.channel + elif all(x == cls.user for x in datatypes): + return cls.user elif set(datatypes) <= {cls.role, cls.user}: return cls.mentionable else: From a23dc6269bb09f8157ee29a87a66b4f68818ac62 Mon Sep 17 00:00:00 2001 From: plun1331 Date: Mon, 16 Nov 2026 11:29:07 -0800 Subject: [PATCH 2/4] feat: file_types --- discord/commands/options.py | 14 ++++++++++++++ discord/components.py | 5 +++++ discord/types/components.py | 1 + discord/ui/file_upload.py | 24 ++++++++++++++++++++++++ 4 files changed, 44 insertions(+) diff --git a/discord/commands/options.py b/discord/commands/options.py index 21dd422c43..2bb4af8e4e 100644 --- a/discord/commands/options.py +++ b/discord/commands/options.py @@ -59,6 +59,7 @@ from ..enums import ChannelType from ..enums import Enum as DiscordEnum from ..enums import SlashCommandOptionType +from ..errors import InvalidArgument from ..utils import MISSING, basic_autocomplete if TYPE_CHECKING: @@ -194,6 +195,11 @@ class Option: description_localizations: Dict[:class:`str`, :class:`str`] The description localizations for this option. The values of this should be ``"locale": "description"``. See `here `_ for a list of valid locales. + file_types: list[:class:`str`] + The file types to filter by. Only checks the file extension. + Only applies to Options with an :attr:`input_type` of :class:`discord.SlashCommandOptionType.attachment`. + If this argument is used, :attr:`input_type` will be ignored. + See `Discord's documentation `__ for more information. Examples -------- @@ -253,9 +259,15 @@ def __init__( self.description = description or "No description provided" self.channel_types: list[ChannelType] = kwargs.pop("channel_types", []) + self.file_types: list[str] = kwargs.pop("file_types", []) + + if self.channel_types and self.file_types: + raise InvalidArgument("cannot pass both channel_types and file_types") if self.channel_types: self.input_type = SlashCommandOptionType.channel + elif self.file_types: + self.input_type = SlashCommandOptionType.attachment elif isinstance(input_type, SlashCommandOptionType): self.input_type = input_type else: @@ -452,6 +464,8 @@ def to_dict(self) -> dict: as_dict["min_length"] = self.min_length if self.max_length is not None: as_dict["max_length"] = self.max_length + if self.file_types: + as_dict["file_types"] = self.file_types return as_dict diff --git a/discord/components.py b/discord/components.py index 8db2c48506..7cc37f7dfc 100644 --- a/discord/components.py +++ b/discord/components.py @@ -1398,6 +1398,7 @@ class FileUpload(Component): "max_values", "required", "id", + "file_types", ) __repr_info__: ClassVar[tuple[str, ...]] = __slots__ @@ -1410,6 +1411,7 @@ def __init__(self, data: FileUploadComponentPayload): self.min_values: int | None = data.get("min_values", None) self.max_values: int | None = data.get("max_values", None) self.required: bool = data.get("required", True) + self.file_types: list[str] | None = data.get("file_types") def to_dict(self) -> FileUploadComponentPayload: payload = { @@ -1428,6 +1430,9 @@ def to_dict(self) -> FileUploadComponentPayload: if not self.required: payload["required"] = self.required + if self.file_types: + payload["file_types"] = self.file_types + return payload # type: ignore diff --git a/discord/types/components.py b/discord/types/components.py index 6a83fb5740..0224122296 100644 --- a/discord/types/components.py +++ b/discord/types/components.py @@ -174,6 +174,7 @@ class FileUploadComponent(BaseComponent): max_values: NotRequired[int] min_values: NotRequired[int] required: NotRequired[bool] + file_types: NotRequired[list[str]] class RadioGroupOption(TypedDict): diff --git a/discord/ui/file_upload.py b/discord/ui/file_upload.py index f7d15e394d..bdf34313fb 100644 --- a/discord/ui/file_upload.py +++ b/discord/ui/file_upload.py @@ -58,6 +58,9 @@ class FileUpload(ModalItem): Whether the file upload field is required or not. Defaults to ``True``. id: :class:`int` | :obj:`None` The file upload field's ID. + file_types: list[:class:`str`] + The types accepted in this file upload. This only filters by file extension. + See `Discord's documentation `__ for more information. """ __item_repr_attributes__: tuple[str, ...] = ( @@ -66,6 +69,7 @@ class FileUpload(ModalItem): "max_values", "custom_id", "id", + "file_types", ) def __init__( @@ -76,6 +80,7 @@ def __init__( max_values: int | None = None, required: bool = True, id: int | None = None, + file_types: list[str] | None = None ): super().__init__() if min_values and (min_values < 0 or min_values > 10): @@ -86,6 +91,8 @@ def __init__( raise TypeError( f"expected custom_id to be str, not {custom_id.__class__.__name__}" ) + if file_types and len(file_types) > 10: + raise ValueError("file_types must be less than 10 items") if not isinstance(required, bool): raise TypeError(f"required must be bool not {required.__class__.__name__}") @@ -98,6 +105,7 @@ def __init__( max_values=max_values, required=required, id=id, + file_types=file_types, ) def _generate_underlying( @@ -107,6 +115,7 @@ def _generate_underlying( max_values: int | None = None, required: bool | None = None, id: int | None = None, + file_types: list[str] | None = None, ) -> FileUploadComponent: super()._generate_underlying(FileUploadComponent) return FileUploadComponent._raw_construct( @@ -116,6 +125,7 @@ def _generate_underlying( max_values=max_values if max_values is not None else self.max_values, required=required if required is not None else self.required, id=id or self.id, + file_types=file_types, ) @property @@ -168,6 +178,20 @@ def required(self, value: bool): raise TypeError(f"required must be bool not {value.__class__.__name__}") # type: ignore self.underlying.required = bool(value) + @property + def file_types(self) -> list[str] | None: + """ + The file types to filter by. Only checks the file extension. + See `Discord's documentation `__ for more information. + """ + return self.underlying.file_types + + @file_types.setter + def file_types(self, value: list[str] | None) -> None: + if value and len(value) > 10: + raise ValueError("file_types must be less than 10 items") + self.underlying.file_types = value + @property def values(self) -> list[Attachment] | None: """The files that were uploaded to the field. This will be ``None`` if the file upload has not been submitted via a modal yet.""" From 59158b5315fd4fe780ac229d69ede036dbcf6b41 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 16 Nov 2026 19:31:23 +0000 Subject: [PATCH 3/4] style(pre-commit): auto fixes from pre-commit.com hooks --- discord/commands/options.py | 2 +- discord/ui/file_upload.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/discord/commands/options.py b/discord/commands/options.py index 2bb4af8e4e..7676697072 100644 --- a/discord/commands/options.py +++ b/discord/commands/options.py @@ -196,7 +196,7 @@ class Option: The description localizations for this option. The values of this should be ``"locale": "description"``. See `here `_ for a list of valid locales. file_types: list[:class:`str`] - The file types to filter by. Only checks the file extension. + The file types to filter by. Only checks the file extension. Only applies to Options with an :attr:`input_type` of :class:`discord.SlashCommandOptionType.attachment`. If this argument is used, :attr:`input_type` will be ignored. See `Discord's documentation `__ for more information. diff --git a/discord/ui/file_upload.py b/discord/ui/file_upload.py index bdf34313fb..dbf512c976 100644 --- a/discord/ui/file_upload.py +++ b/discord/ui/file_upload.py @@ -80,7 +80,7 @@ def __init__( max_values: int | None = None, required: bool = True, id: int | None = None, - file_types: list[str] | None = None + file_types: list[str] | None = None, ): super().__init__() if min_values and (min_values < 0 or min_values > 10): @@ -181,7 +181,7 @@ def required(self, value: bool): @property def file_types(self) -> list[str] | None: """ - The file types to filter by. Only checks the file extension. + The file types to filter by. Only checks the file extension. See `Discord's documentation `__ for more information. """ return self.underlying.file_types From a079caa30e6df10bdda920f3e6777479aad7d4b4 Mon Sep 17 00:00:00 2001 From: plun1331 Date: Mon, 16 Nov 2026 11:29:07 -0800 Subject: [PATCH 4/4] feat: file_types --- discord/commands/options.py | 14 ++++++++++++++ discord/components.py | 5 +++++ discord/types/components.py | 1 + discord/ui/file_upload.py | 24 ++++++++++++++++++++++++ 4 files changed, 44 insertions(+) diff --git a/discord/commands/options.py b/discord/commands/options.py index 21dd422c43..2bb4af8e4e 100644 --- a/discord/commands/options.py +++ b/discord/commands/options.py @@ -59,6 +59,7 @@ from ..enums import ChannelType from ..enums import Enum as DiscordEnum from ..enums import SlashCommandOptionType +from ..errors import InvalidArgument from ..utils import MISSING, basic_autocomplete if TYPE_CHECKING: @@ -194,6 +195,11 @@ class Option: description_localizations: Dict[:class:`str`, :class:`str`] The description localizations for this option. The values of this should be ``"locale": "description"``. See `here `_ for a list of valid locales. + file_types: list[:class:`str`] + The file types to filter by. Only checks the file extension. + Only applies to Options with an :attr:`input_type` of :class:`discord.SlashCommandOptionType.attachment`. + If this argument is used, :attr:`input_type` will be ignored. + See `Discord's documentation `__ for more information. Examples -------- @@ -253,9 +259,15 @@ def __init__( self.description = description or "No description provided" self.channel_types: list[ChannelType] = kwargs.pop("channel_types", []) + self.file_types: list[str] = kwargs.pop("file_types", []) + + if self.channel_types and self.file_types: + raise InvalidArgument("cannot pass both channel_types and file_types") if self.channel_types: self.input_type = SlashCommandOptionType.channel + elif self.file_types: + self.input_type = SlashCommandOptionType.attachment elif isinstance(input_type, SlashCommandOptionType): self.input_type = input_type else: @@ -452,6 +464,8 @@ def to_dict(self) -> dict: as_dict["min_length"] = self.min_length if self.max_length is not None: as_dict["max_length"] = self.max_length + if self.file_types: + as_dict["file_types"] = self.file_types return as_dict diff --git a/discord/components.py b/discord/components.py index 8db2c48506..7cc37f7dfc 100644 --- a/discord/components.py +++ b/discord/components.py @@ -1398,6 +1398,7 @@ class FileUpload(Component): "max_values", "required", "id", + "file_types", ) __repr_info__: ClassVar[tuple[str, ...]] = __slots__ @@ -1410,6 +1411,7 @@ def __init__(self, data: FileUploadComponentPayload): self.min_values: int | None = data.get("min_values", None) self.max_values: int | None = data.get("max_values", None) self.required: bool = data.get("required", True) + self.file_types: list[str] | None = data.get("file_types") def to_dict(self) -> FileUploadComponentPayload: payload = { @@ -1428,6 +1430,9 @@ def to_dict(self) -> FileUploadComponentPayload: if not self.required: payload["required"] = self.required + if self.file_types: + payload["file_types"] = self.file_types + return payload # type: ignore diff --git a/discord/types/components.py b/discord/types/components.py index 6a83fb5740..0224122296 100644 --- a/discord/types/components.py +++ b/discord/types/components.py @@ -174,6 +174,7 @@ class FileUploadComponent(BaseComponent): max_values: NotRequired[int] min_values: NotRequired[int] required: NotRequired[bool] + file_types: NotRequired[list[str]] class RadioGroupOption(TypedDict): diff --git a/discord/ui/file_upload.py b/discord/ui/file_upload.py index f7d15e394d..bdf34313fb 100644 --- a/discord/ui/file_upload.py +++ b/discord/ui/file_upload.py @@ -58,6 +58,9 @@ class FileUpload(ModalItem): Whether the file upload field is required or not. Defaults to ``True``. id: :class:`int` | :obj:`None` The file upload field's ID. + file_types: list[:class:`str`] + The types accepted in this file upload. This only filters by file extension. + See `Discord's documentation `__ for more information. """ __item_repr_attributes__: tuple[str, ...] = ( @@ -66,6 +69,7 @@ class FileUpload(ModalItem): "max_values", "custom_id", "id", + "file_types", ) def __init__( @@ -76,6 +80,7 @@ def __init__( max_values: int | None = None, required: bool = True, id: int | None = None, + file_types: list[str] | None = None ): super().__init__() if min_values and (min_values < 0 or min_values > 10): @@ -86,6 +91,8 @@ def __init__( raise TypeError( f"expected custom_id to be str, not {custom_id.__class__.__name__}" ) + if file_types and len(file_types) > 10: + raise ValueError("file_types must be less than 10 items") if not isinstance(required, bool): raise TypeError(f"required must be bool not {required.__class__.__name__}") @@ -98,6 +105,7 @@ def __init__( max_values=max_values, required=required, id=id, + file_types=file_types, ) def _generate_underlying( @@ -107,6 +115,7 @@ def _generate_underlying( max_values: int | None = None, required: bool | None = None, id: int | None = None, + file_types: list[str] | None = None, ) -> FileUploadComponent: super()._generate_underlying(FileUploadComponent) return FileUploadComponent._raw_construct( @@ -116,6 +125,7 @@ def _generate_underlying( max_values=max_values if max_values is not None else self.max_values, required=required if required is not None else self.required, id=id or self.id, + file_types=file_types, ) @property @@ -168,6 +178,20 @@ def required(self, value: bool): raise TypeError(f"required must be bool not {value.__class__.__name__}") # type: ignore self.underlying.required = bool(value) + @property + def file_types(self) -> list[str] | None: + """ + The file types to filter by. Only checks the file extension. + See `Discord's documentation `__ for more information. + """ + return self.underlying.file_types + + @file_types.setter + def file_types(self, value: list[str] | None) -> None: + if value and len(value) > 10: + raise ValueError("file_types must be less than 10 items") + self.underlying.file_types = value + @property def values(self) -> list[Attachment] | None: """The files that were uploaded to the field. This will be ``None`` if the file upload has not been submitted via a modal yet."""