diff --git a/CHANGELOG.md b/CHANGELOG.md index f8e21fdf4e..abbed4d406 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,10 @@ These changes are available on the `master` branch, but have not yet been releas - Added `RoleColours.HOLOGRAPHIC_PRIMARY`, `RoleColours.HOLOGRAPHIC_SECONDARY`, and `RoleColours.HOLOGRAPHIC_TERTIARY` class constants. ([#3268](https://github.com/Pycord-Development/pycord/pull/3268)) +- Added `ChannelFlags.is_spoiler_channel` and `.is_spoiler()` function to all applicable + channel types. ([#3252](https://github.com/Pycord-Development/pycord/pull/3252)) +- Added `spoiler` parameter to the `edit()` function of all applicable channel types. + ([#3252](https://github.com/Pycord-Development/pycord/pull/3252)) ### Changed diff --git a/discord/channel.py b/discord/channel.py index 7cb6fa2698..dff8ffe58a 100644 --- a/discord/channel.py +++ b/discord/channel.py @@ -320,6 +320,13 @@ def is_nsfw(self) -> bool: """Checks if the channel is NSFW.""" return self.nsfw + def is_spoiler(self) -> bool: + """Checks if the channel is a spoiler channel. + + .. versionadded:: 2.9 + """ + return self.flags.is_spoiler_channel + @property def last_message(self) -> Message | None: """Fetches the last message from this channel in cache. @@ -812,6 +819,7 @@ async def edit( default_thread_slowmode_delay: int = ..., type: ChannelType = ..., overwrites: Mapping[Role | Member | Snowflake, PermissionOverwrite] = ..., + spoiler: bool = ..., ) -> TextChannel | None: ... @overload @@ -868,6 +876,10 @@ async def edit(self, *, reason=None, **options): The new default slowmode delay in seconds for threads created in this channel. .. versionadded:: 2.3 + spoiler: :class:`bool` + Whether the channel should be a spoiler channel. Mutually exclusive with :attr:`nsfw`. + + .. versionadded:: 2.9 Returns ------- @@ -885,6 +897,10 @@ async def edit(self, *, reason=None, **options): HTTPException Editing the channel failed. """ + if "spoiler" in options: + options["flags"] = ChannelFlags._from_value(self.flags.value) + options["flags"].is_spoiler_channel = options.pop("spoiler") + payload = await self._edit(options, reason=reason) if payload is not None: # the payload will always be the proper channel payload @@ -1126,6 +1142,7 @@ async def edit( available_tags: list[ForumTag] = ..., require_tag: bool = ..., overwrites: Mapping[Role | Member | Snowflake, PermissionOverwrite] = ..., + spoiler: bool = ..., ) -> ForumChannel | None: ... @overload @@ -1188,6 +1205,10 @@ async def edit(self, *, reason=None, **options): Whether a tag should be required to be specified when creating a thread in this channel. .. versionadded:: 2.3 + spoiler: :class:`bool` + Whether the channel should be a spoiler channel. Mutually exclusive with :attr:`nsfw`. + + .. versionadded:: 2.9 Returns ------- @@ -1208,6 +1229,10 @@ async def edit(self, *, reason=None, **options): if "require_tag" in options: options["flags"] = ChannelFlags._from_value(self.flags.value) options["flags"].require_tag = options.pop("require_tag") + if "spoiler" in options: + if "flags" not in options: + options["flags"] = ChannelFlags._from_value(self.flags.value) + options["flags"].is_spoiler_channel = options.pop("spoiler") payload = await self._edit(options, reason=reason) if payload is not None: @@ -1507,6 +1532,7 @@ async def edit( require_tag: bool = ..., hide_media_download_options: bool = ..., overwrites: Mapping[Role | Member | Snowflake, PermissionOverwrite] = ..., + spoiler: bool = ..., ) -> ForumChannel | None: ... async def edit(self, *, reason=None, **options): @@ -1563,6 +1589,11 @@ async def edit(self, *, reason=None, **options): hide_media_download_options: :class:`bool` Whether media download options should be hidden in this media channel. + spoiler: :class:`bool` + Whether the channel should be a spoiler channel. Mutually exclusive with :attr:`nsfw`. + + .. versionadded:: 2.9 + Returns ------- Optional[:class:`.MediaChannel`] @@ -1580,14 +1611,18 @@ async def edit(self, *, reason=None, **options): Editing the channel failed. """ - if "require_tag" in options or "hide_media_download_options" in options: + if ( + "require_tag" in options + or "hide_media_download_options" in options + or "spoiler" in options + ): flags = ChannelFlags._from_value(self.flags.value) flags.require_tag = options.pop("require_tag", flags.require_tag) flags.hide_media_download_options = options.pop( "hide_media_download_options", flags.hide_media_download_options ) + flags.is_spoiler_channel = options.pop("spoiler", flags.is_spoiler_channel) options["flags"] = flags - payload = await self._edit(options, reason=reason) if payload is not None: # the payload will always be the proper channel payload @@ -1818,6 +1853,13 @@ def is_nsfw(self) -> bool: """Checks if the channel is NSFW.""" return self.nsfw + def is_spoiler(self) -> bool: + """Checks if the channel is a spoiler channel. + + .. versionadded:: 2.9 + """ + return self.flags.is_spoiler_channel + @property def last_message(self) -> Message | None: """Fetches the last message from this channel in cache. @@ -2099,6 +2141,7 @@ async def edit( slowmode_delay: int = ..., nsfw: bool = ..., reason: str | None = ..., + spoiler: bool = ..., ) -> VoiceChannel | None: ... @overload @@ -2157,6 +2200,11 @@ async def edit(self, *, reason=None, **options): .. versionadded:: 2.7 + spoiler: :class:`bool` + Whether the channel should be a spoiler channel. Mutually exclusive with :attr:`nsfw`. + + .. versionadded:: 2.9 + Returns ------- Optional[:class:`.VoiceChannel`] @@ -2172,6 +2220,9 @@ async def edit(self, *, reason=None, **options): HTTPException Editing the channel failed. """ + if "spoiler" in options: + options["flags"] = ChannelFlags._from_value(self.flags.value) + options["flags"].is_spoiler_channel = options.pop("spoiler") payload = await self._edit(options, reason=reason) if payload is not None: @@ -2406,6 +2457,13 @@ def is_nsfw(self) -> bool: """Checks if the channel is NSFW.""" return self.nsfw + def is_spoiler(self) -> bool: + """Checks if the channel is a spoiler channel. + + .. versionadded:: 2.9 + """ + return self.flags.is_spoiler_channel + @property def last_message(self) -> Message | None: """Fetches the last message from this channel in cache. diff --git a/discord/flags.py b/discord/flags.py index 62f67dfc2a..a3668286a4 100644 --- a/discord/flags.py +++ b/discord/flags.py @@ -1586,6 +1586,14 @@ def hide_media_download_options(self): """ return 1 << 15 + @flag_value + def is_spoiler_channel(self): + """:class:`bool`: Returns ``True`` if the channel is a spoiler channel. + + .. versionadded:: 2.9 + """ + return 1 << 21 + @fill_with_flags() class AttachmentFlags(BaseFlags):