Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
b1ded01
Add spoiler channel flag and functions
ToothyDev Jun 5, 2026
7b79faa
Add editing spoiler flag to channel editing functions
ToothyDev Jun 5, 2026
9d09881
Merge branch 'master' into feat/spoiler-channels
ToothyDev Jun 22, 2026
65bfc90
Merge branch 'master' into feat/spoiler-channels
Lulalaby Jul 30, 2026
f426f25
fix: changelog
Lulalaby Jul 30, 2026
cb9f534
Merge branch 'master' into feat/spoiler-channels
Lulalaby Jul 30, 2026
7aaad87
Merge branch 'master' into feat/spoiler-channels
ToothyDev Aug 4, 2026
769cc08
Make spoiler attribute a property
ToothyDev Aug 4, 2026
19531ba
Add mutual exclusivity check for nsfw and spoiler options
ToothyDev Aug 4, 2026
16309ed
Merge branch 'master' into feat/spoiler-channels
ToothyDev Aug 4, 2026
68608ab
Adjust changelog to new naming
ToothyDev Aug 10, 2026
763c13f
Merge branch 'master' into feat/spoiler-channels
Lulalaby Aug 10, 2026
f2cb6bb
Add channel creation support with spoiler flag
ToothyDev Aug 10, 2026
9508a82
Add channel creation support with spoiler flag
ToothyDev Aug 10, 2026
4f41083
Minor documentation formatting
ToothyDev Aug 10, 2026
7327338
Fix value defaulting
ToothyDev Aug 10, 2026
57e3dd7
Address code review change requests
ToothyDev Aug 10, 2026
06167d2
Warn when passing both nsfw and spoiler options
ToothyDev Aug 10, 2026
c8f6f61
Add overloads for voice and forum channels
ToothyDev Aug 11, 2026
b56e022
Apply change requests from code review
ToothyDev Aug 11, 2026
2582634
Apply change requests from code review
ToothyDev Aug 11, 2026
ccca218
Fix edit() overloads
ToothyDev Aug 12, 2026
74dda97
Address change requests
ToothyDev Aug 13, 2026
0e64964
Merge branch 'master' into feat/spoiler-channels
ToothyDev Aug 14, 2026
8fcaf91
fixup! Merge branch 'master' into feat/spoiler-channels
ToothyDev Aug 14, 2026
414bd34
Address change requests
ToothyDev Aug 15, 2026
ca98dd2
Address change requests
ToothyDev Aug 17, 2026
7257401
Address change requests and unify warnings to be notes
ToothyDev Aug 23, 2026
3eeab68
Merge branch 'master' into feat/spoiler-channels
ToothyDev Aug 23, 2026
bc6656f
Update CHANGELOG.md
ToothyDev Sep 12, 2026
e1be8da
Merge branch 'master' into feat/spoiler-channels
Paillat-dev Sep 17, 2026
9f74834
Update docstrings to use uppercase "NSFW"
ToothyDev Sep 17, 2026
61df98c
Apply change requests
ToothyDev Sep 18, 2026
b42aa42
Merge branch 'master' into feat/spoiler-channels
Paillat-dev Oct 2, 2026
a72f7e0
Remove spoiler functionality for stage channels
ToothyDev Oct 2, 2026
225cc81
Apply change request
ToothyDev Oct 2, 2026
937316a
Apply change requests
ToothyDev Oct 4, 2026
553ba6c
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 4, 2026
9a071c5
Merge branch 'master' into feat/spoiler-channels
ToothyDev Oct 22, 2026
eff44b5
Merge branch 'master' into feat/spoiler-channels
ToothyDev Nov 2, 2026
626cc48
Merge branch 'master' into feat/spoiler-channels
ToothyDev Nov 5, 2026
1f8afbe
chore: Update old `Optional[...]` syntax to use new `type | None` syn…
ToothyDev Nov 10, 2026
250d4aa
Merge branch 'master' into feat/spoiler-channels
ToothyDev Nov 10, 2026
767203a
Merge branch 'master' into feat/spoiler-channels
ToothyDev Nov 15, 2026
8be7173
Merge branch 'master' into feat/spoiler-channels
Paillat-dev Nov 17, 2026
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ These changes are available on the `master` branch, but have not yet been releas
([#3152](https://github.com/Pycord-Development/pycord/pull/3152))
- Added `Embed.components` and `DesignerView.from_embed`.
([#3443](https://github.com/Pycord-Development/pycord/pull/3443))
- Added support for spoiler channels.
([#3252](https://github.com/Pycord-Development/pycord/pull/3252))

### Changed

Expand Down
218 changes: 206 additions & 12 deletions discord/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@
from __future__ import annotations

import datetime
import warnings
from collections.abc import Callable, Iterable, Mapping, Sequence
from typing import (
TYPE_CHECKING,
Any,
Literal,
NamedTuple,
TypeVar,
overload,
Expand Down Expand Up @@ -317,6 +319,17 @@ def is_nsfw(self) -> bool:
"""Checks if the channel is NSFW."""
return self.nsfw

@property
def spoiler(self) -> bool:
"""Checks if the channel is a spoiler channel.
Comment thread
ToothyDev marked this conversation as resolved.
Resolved

.. note::
This is an alias for :attr:`ChannelFlags.is_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 @@ -809,6 +822,26 @@ async def edit(
default_thread_slowmode_delay: int = ...,
type: ChannelType = ...,
overwrites: Mapping[Role | Member | Snowflake, PermissionOverwrite] = ...,
spoiler: Literal[False] = ...,
) -> TextChannel | None: ...

@overload
async def edit(
self,
*,
reason: str | None = ...,
name: str = ...,
topic: str = ...,
position: int = ...,
nsfw: Literal[False] = ...,
sync_permissions: bool = ...,
category: CategoryChannel | None = ...,
slowmode_delay: int = ...,
default_auto_archive_duration: ThreadArchiveDuration = ...,
default_thread_slowmode_delay: int = ...,
type: ChannelType = ...,
overwrites: Mapping[Role | Member | Snowflake, PermissionOverwrite] = ...,
spoiler: bool = ...,
Comment thread
ToothyDev marked this conversation as resolved.
Resolved
) -> TextChannel | None: ...

@overload
Expand Down Expand Up @@ -841,6 +874,10 @@ async def edit(self, *, reason=None, **options):
The new channel's position.
nsfw: :class:`bool`
Whether the channel is marked as NSFW.

.. note::
This setting is mutually exclusive with :attr:`spoiler`. Applying this to a spoiler channel will convert it to an NSFW channel.
Passing both as ``True`` will make the channel an NSFW channel.
sync_permissions: :class:`bool`
Whether to sync permissions with the channel's new or pre-existing
category. Defaults to ``False``.
Expand All @@ -865,6 +902,13 @@ 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

.. note::
Passing both this and ``nsfw`` as ``True`` will mark the channel as NSFW and ignore the spoiler flag.

Returns
-------
Expand All @@ -882,6 +926,18 @@ async def edit(self, *, reason=None, **options):
HTTPException
Editing the channel failed.
"""
if "spoiler" in options:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nsfw docstring says passing nsfw=True to a spoiler channel converts it to NSFW, but this block only runs when spoiler is passed. edit(nsfw=True) alone never clears is_spoiler_channel, so the documented behavior isn't implemented. Either handle nsfw=True independently of spoiler (clear the bit) or drop that sentence from the docstring.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tested this with the current code. Passing nsfw=True to a spoiler channel converts it, and channel.spoiler returns False as expected

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, fine.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So just to make sure I understand @ToothyDev, spoiler to nsfw implicitly works fine but nsfw to spoiler implicitly fails ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. I think this was a dicussion way early in the PR where catching all the specific cases was really complicated and so it was scrapped, since the API doesn't reject it, it just doesn't do anything

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like the only explicitly documented behavior is

Can only be set if channel's nsfw is false

for spoiler state, and nothing about the other way around. I am not sure however if we should still rely on the API for the rest.

@Lulalaby Do you have some insight maybe ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Lulalaby wdyt

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ToothyDev Ive been ootl for too long but it seems to me like I can't find here where "nsfw to spoiler implicitly fails" is handled.

options["flags"] = ChannelFlags._from_value(self.flags.value)
options["flags"].is_spoiler_channel = options["spoiler"]

if options.get("nsfw") and options.get("spoiler"):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if options.get("nsfw") and options.get("spoiler"):
if options.get("nsfw"):

"spoiler" is already checked to be in options above no ?

warnings.warn(
"The NSFW setting is mutually exclusive with the spoiler setting. "
"The channel will become an NSFW channel.",
stacklevel=2,
)
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 @@ -1123,6 +1179,31 @@ async def edit(
available_tags: list[ForumTag] = ...,
require_tag: bool = ...,
overwrites: Mapping[Role | Member | Snowflake, PermissionOverwrite] = ...,
spoiler: Literal[False] = ...,
) -> ForumChannel | None: ...

@overload
async def edit(
self,
*,
reason: str | None = ...,
name: str = ...,
topic: str = ...,
position: int = ...,
nsfw: Literal[False] = ...,
sync_permissions: bool = ...,
category: CategoryChannel | None = ...,
slowmode_delay: int = ...,
default_auto_archive_duration: (
ThreadArchiveDuration | ThreadArchiveDurationEnum
) = ...,
default_thread_slowmode_delay: int = ...,
default_sort_order: SortOrder = ...,
default_reaction_emoji: GuildEmoji | int | str | None = ...,
available_tags: list[ForumTag] = ...,
require_tag: bool = ...,
overwrites: Mapping[Role | Member | Snowflake, PermissionOverwrite] = ...,
spoiler: bool = ...,
) -> ForumChannel | None: ...

@overload
Expand All @@ -1145,7 +1226,10 @@ async def edit(self, *, reason=None, **options):
position: :class:`int`
The new channel's position.
nsfw: :class:`bool`
Whether the channel is marked as NSFW.
Whether the channel is marked as NSFW. Mutually exclusive with :attr:`spoiler`.

.. note::
Passing both this and ``spoiler`` as ``True`` will mark the channel as NSFW and ignore the spoiler flag.
sync_permissions: :class:`bool`
Whether to sync permissions with the channel's new or pre-existing
category. Defaults to ``False``.
Expand Down Expand Up @@ -1185,6 +1269,13 @@ 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`.
Comment thread
Paillat-dev marked this conversation as resolved.
Resolved

.. versionadded:: 2.9
Comment thread
ToothyDev marked this conversation as resolved.
Resolved

.. note::
Passing both this and ``nsfw`` as ``True`` will mark the channel as NSFW and ignore the spoiler flag.

Returns
-------
Expand All @@ -1205,6 +1296,19 @@ 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
) # Reconstruct existing flags
options["flags"].is_spoiler_channel = options["spoiler"]

if options.get("nsfw") and options.get("spoiler"):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above

warnings.warn(
"The NSFW setting is mutually exclusive with the spoiler setting. The channel will become an NSFW channel.",
stacklevel=2,
)
options.pop("spoiler")

payload = await self._edit(options, reason=reason)
if payload is not None:
Expand Down Expand Up @@ -1504,10 +1608,31 @@ async def edit(
require_tag: bool = ...,
hide_media_download_options: bool = ...,
overwrites: Mapping[Role | Member | Snowflake, PermissionOverwrite] = ...,
spoiler: Literal[False] = ...,
) -> MediaChannel | None: ...

@overload
async def edit(self) -> MediaChannel | None: ...
async def edit(
self,
*,
reason: str | None = ...,
name: str = ...,
topic: str = ...,
position: int = ...,
nsfw: Literal[False] = ...,
sync_permissions: bool = ...,
category: CategoryChannel | None = ...,
slowmode_delay: int = ...,
default_auto_archive_duration: ThreadArchiveDuration = ...,
default_thread_slowmode_delay: int = ...,
default_sort_order: SortOrder = ...,
default_reaction_emoji: GuildEmoji | int | str | None = ...,
available_tags: list[ForumTag] = ...,
require_tag: bool = ...,
hide_media_download_options: bool = ...,
overwrites: Mapping[Role | Member | Snowflake, PermissionOverwrite] = ...,
spoiler: bool = ...,
) -> MediaChannel | None: ...

async def edit(self, *, reason=None, **options):
"""|coro|
Expand All @@ -1526,7 +1651,10 @@ async def edit(self, *, reason=None, **options):
position: :class:`int`
The new channel's position.
nsfw: :class:`bool`
Whether the channel is marked as NSFW.
Whether the channel is marked as NSFW. Mutually exclusive with :attr:`spoiler`.

.. note::
Passing both this and ``spoiler`` as ``True`` will mark the channel as NSFW and ignore the spoiler flag.
sync_permissions: :class:`bool`
Whether to sync permissions with the channel's new or pre-existing
category. Defaults to ``False``.
Expand Down Expand Up @@ -1563,6 +1691,14 @@ 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

Comment thread
ToothyDev marked this conversation as resolved.
Resolved
.. note::
Passing both this and ``nsfw`` as ``True`` will mark the channel as NSFW and ignore the spoiler flag.

Returns
-------
:class:`.MediaChannel` | :obj:`None`
Expand All @@ -1580,14 +1716,20 @@ 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", "hide_media_download_options", "spoiler"} & options.keys():
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
)
if options.get("nsfw") and options.get("spoiler"):
warnings.warn(
"The NSFW setting is mutually exclusive with the spoiler setting. "
"The channel will become an NSFW channel.",
stacklevel=2,
)
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 @@ -1837,19 +1979,30 @@ def is_nsfw(self) -> bool:
"""Checks if the channel is NSFW."""
return self.nsfw

@property
def spoiler(self) -> bool:
Comment thread
ToothyDev marked this conversation as resolved.
Resolved
"""Checks if the channel is a spoiler channel.

Comment thread
ToothyDev marked this conversation as resolved.
Resolved
.. note::
This is an alias for :attr:`ChannelFlags.is_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.

The message might not be valid or point to an existing message.

.. admonition:: Reliable Fetching
:class: helpful
.. admonition:: Reliable Fetching
:class: helpful

For a slightly more reliable method of fetching the
last message, consider using either :meth:`history`
or :meth:`fetch_message` with the :attr:`last_message_id`
attribute.
For a slightly more reliable method of fetching the
last message, consider using either :meth:`history`
or :meth:`fetch_message` with the :attr:`last_message_id`
attribute.

Returns
-------
Expand Down Expand Up @@ -2118,6 +2271,26 @@ async def edit(
slowmode_delay: int = ...,
nsfw: bool = ...,
reason: str | None = ...,
spoiler: Literal[False] = ...,
) -> VoiceChannel | None: ...

@overload
async def edit(
self,
*,
name: str = ...,
bitrate: int = ...,
user_limit: int = ...,
position: int = ...,
sync_permissions: int = ...,
Comment thread
ToothyDev marked this conversation as resolved.
Resolved
category: CategoryChannel | None = ...,
overwrites: Mapping[Role | Member, PermissionOverwrite] = ...,
rtc_region: VoiceRegion | None = ...,
video_quality_mode: VideoQualityMode = ...,
slowmode_delay: int = ...,
nsfw: Literal[False] = ...,
reason: str | None = ...,
spoiler: bool = ...,
) -> VoiceChannel | None: ...

@overload
Expand Down Expand Up @@ -2176,10 +2349,21 @@ async def edit(self, *, reason=None, **options):
A value of `0` disables slowmode. The maximum value possible is `21600`.

nsfw: :class:`bool`
Whether the channel is marked as NSFW.
Whether the channel is marked as NSFW. Mutually exclusive with :attr:`spoiler`.

.. versionadded:: 2.7

.. note::
Passing both this and ``spoiler`` as ``True`` will mark the channel as NSFW and ignore the spoiler flag.

spoiler: :class:`bool`
Whether the channel should be a spoiler channel. Mutually exclusive with :attr:`nsfw`.

.. versionadded:: 2.9

.. note::
Passing both this and ``nsfw`` as ``True`` will mark the channel as NSFW and ignore the spoiler flag.

Returns
-------
:class:`.VoiceChannel` | :obj:`None`
Expand All @@ -2195,6 +2379,16 @@ 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["spoiler"]

if options.get("nsfw") and options.get("spoiler"):
warnings.warn(
"NSFW setting is mutually exclusive with spoiler setting. Channel will become an NSFW channel.",
stacklevel=2,
)
options.pop("spoiler")

payload = await self._edit(options, reason=reason)
if payload is not None:
Expand Down
8 changes: 8 additions & 0 deletions discord/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -1628,6 +1628,14 @@ def channel_obfuscated(self):

return 1 << 17

@flag_value
def is_spoiler_channel(self):
Comment thread
ToothyDev marked this conversation as resolved.
Resolved
""":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
Loading