Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
62 changes: 60 additions & 2 deletions discord/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
-------
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
-------
Expand All @@ -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:
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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`]
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -2091,6 +2133,7 @@ async def edit(
slowmode_delay: int = ...,
nsfw: bool = ...,
reason: str | None = ...,
spoiler: bool = ...,
) -> VoiceChannel | None: ...

@overload
Expand Down Expand Up @@ -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`]
Expand All @@ -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:
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions discord/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading