diff --git a/CHANGELOG.md b/CHANGELOG.md index c63b835f8c..3ef775f4c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,11 @@ These changes are available on the `master` branch, but have not yet been releas ### Added +- 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 ### Fixed diff --git a/discord/channel.py b/discord/channel.py index 2a6d5182ac..a39cc1c415 100644 --- a/discord/channel.py +++ b/discord/channel.py @@ -312,6 +312,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. @@ -804,6 +811,7 @@ async def edit( default_thread_slowmode_delay: int = ..., type: ChannelType = ..., overwrites: Mapping[Role | Member | Snowflake, PermissionOverwrite] = ..., + spoiler: bool = ..., ) -> TextChannel | None: ... @overload @@ -860,6 +868,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 ------- @@ -877,6 +889,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 @@ -1118,6 +1134,7 @@ async def edit( available_tags: list[ForumTag] = ..., require_tag: bool = ..., overwrites: Mapping[Role | Member | Snowflake, PermissionOverwrite] = ..., + spoiler: bool = ..., ) -> ForumChannel | None: ... @overload @@ -1180,6 +1197,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 ------- @@ -1200,6 +1221,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: @@ -1499,6 +1524,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): @@ -1555,6 +1581,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`] @@ -1572,14 +1603,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 @@ -1810,6 +1845,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. @@ -2091,6 +2133,7 @@ async def edit( slowmode_delay: int = ..., nsfw: bool = ..., reason: str | None = ..., + spoiler: bool = ..., ) -> VoiceChannel | None: ... @overload @@ -2149,6 +2192,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`] @@ -2164,6 +2212,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: @@ -2398,6 +2449,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 53c1ccd98b..b67240f9c7 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):