Skip to content

docs: Improve docstrings and attribute documentation #2772

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
426bb6a
Update guild.py
Lumabots Mar 29, 2025
6e68b7a
Update channel.py
Lumabots Mar 29, 2025
46aa608
Update guild.py
Lumabots Mar 29, 2025
332e652
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 29, 2025
eff4e52
Update channel.py
Lumabots Mar 29, 2025
477407f
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 29, 2025
e717f67
Update guild.py
Lumabots Mar 29, 2025
13c6037
Update guild.py
Lumabots Mar 29, 2025
c4b7091
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 29, 2025
1d7eb3f
Update CHANGELOG.md
Lumabots Mar 29, 2025
dd0f397
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 29, 2025
340cec3
Update CHANGELOG.md
Lumabots Apr 7, 2025
bc2fef9
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 7, 2025
d8b79ff
Update guild.py
Lumabots Apr 10, 2025
952aab8
Update channel.py
Lumabots Apr 10, 2025
7dd8a7a
Update channel.py
Lumabots Apr 10, 2025
0035a73
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 10, 2025
1ef8618
Merge branch 'master' into channel
Lumabots Apr 30, 2025
757ef9c
fix typo
Lumabots May 1, 2025
cab128e
Update discord/channel.py
Lumabots May 1, 2025
19a83f3
Update discord/channel.py
Lumabots May 1, 2025
913cf87
Update discord/channel.py
Lumabots May 1, 2025
121ae58
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 1, 2025
966b528
feat(channel): deprecate is_nsfw method in CategoryChannel
Lumabots May 9, 2025
691a27c
fix(channel): correct deprecated decorator arguments in CategoryChannel
Lumabots May 9, 2025
45c0f8b
Merge branch 'master' into channel
Lumabots May 9, 2025
e3e2bec
Merge branch 'master' into channel
Lumabots May 22, 2025
ca6a4bf
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 22, 2025
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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ These changes are available on the `master` branch, but have not yet been releas
- Fixed `ForumChannel.edit` allowing `default_reaction_emoji` to be `None`.
([#2739](https://github.com/Pycord-Development/pycord/pull/2739))
- Fixed missing `None` type hints in `Select.__init__`.
([#2746](https://github.com/Pycord-Development/pycord/pull/2746))
([#2746])(https://github.com/Pycord-Development/pycord/pull/2746)
- Fixed parameters for channels And allow creating channels with None as default
reaction ([#2754])(https://github.com/Pycord-Development/pycord/pull/2754)
- Updated `valid_locales` to support `in` and `es-419`.
([#2767](https://github.com/Pycord-Development/pycord/pull/2767))
- Fixed `Webhook.edit` not working with `attachments=[]`.
Expand Down
55 changes: 43 additions & 12 deletions discord/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,8 @@ def _update(self, guild: Guild, data: ForumChannelPayload) -> None:
if self.default_sort_order is not None:
self.default_sort_order = try_enum(SortOrder, self.default_sort_order)

self.default_reaction_emoji = None

reaction_emoji_ctx: dict = data.get("default_reaction_emoji")
if reaction_emoji_ctx is not None:
emoji_name = reaction_emoji_ctx.get("emoji_name")
Expand Down Expand Up @@ -1724,6 +1726,11 @@ class VoiceChannel(discord.abc.Messageable, VocalGuildChannel):
Extra features of the channel.

.. versionadded:: 2.0

nsfw: :class:`bool`
To mark the channel as NSFW or not.

.. versionadded:: 2.7
"""

def __init__(
Expand Down Expand Up @@ -2042,6 +2049,7 @@ async def edit(
rtc_region: VoiceRegion | None = ...,
video_quality_mode: VideoQualityMode = ...,
slowmode_delay: int = ...,
nsfw: bool = ...,
reason: str | None = ...,
) -> VoiceChannel | None: ...

Expand Down Expand Up @@ -2092,6 +2100,15 @@ async def edit(self, *, reason=None, **options):

.. versionadded:: 2.0

slowmode_delay: :class:`int`
Specifies the slowmode rate limit for user in this channel, in seconds.
The maximum value possible is `21600`.

nsfw: :class:`bool`
To mark the channel as NSFW or not.

.. versionadded:: 2.7

Returns
-------
Optional[:class:`.VoiceChannel`]
Expand Down Expand Up @@ -2250,6 +2267,15 @@ class StageChannel(discord.abc.Messageable, VocalGuildChannel):
last_message_id: Optional[:class:`int`]
The ID of the last message sent to this channel. It may not always point to an existing or valid message.
.. versionadded:: 2.5

slowmode_delay: :class:`int`
Specifies the slowmode rate limit for user in this channel, in seconds.
The maximum value possible is `21600`.

nsfw: :class:`bool`
To mark the channel as NSFW or not.

.. versionadded:: 2.7
"""

__slots__ = ("topic",)
Expand Down Expand Up @@ -2734,6 +2760,16 @@ async def edit(self, *, reason=None, **options):

.. versionadded:: 2.0

bitrate: :class:`int`
The channel's preferred audio bitrate in bits per second.

user_limit: :class:`int`
The channel's limit for number of members that can be in a voice channel.

slowmode_delay: :class:`int`
Specifies the slowmode rate limit for user in this channel, in seconds.
The maximum value possible is `21600`.

Returns
-------
Optional[:class:`.StageChannel`]
Expand Down Expand Up @@ -2790,12 +2826,9 @@ class CategoryChannel(discord.abc.GuildChannel, Hashable):
position: Optional[:class:`int`]
The position in the category list. This is a number that starts at 0. e.g. the
top category is position 0. Can be ``None`` if the channel was received in an interaction.
nsfw: :class:`bool`
If the channel is marked as "not safe for work".

.. note::

To check if the channel or the guild of that channel are marked as NSFW, consider :meth:`is_nsfw` instead.
flags: :class:`ChannelFlags`
Extra features of the channel.

Expand Down Expand Up @@ -2824,7 +2857,7 @@ def __init__(
def __repr__(self) -> str:
return (
"<CategoryChannel"
f" id={self.id} name={self.name!r} position={self.position} nsfw={self.nsfw}>"
f" id={self.id} name={self.name!r} position={self.position}"
)

def _update(self, guild: Guild, data: CategoryChannelPayload) -> None:
Expand All @@ -2835,7 +2868,6 @@ def _update(self, guild: Guild, data: CategoryChannelPayload) -> None:

# This data may be missing depending on how this object is being created/updated
if not data.pop("_invoke_flag", False):
self.nsfw: bool = data.get("nsfw", False)
self.position: int = data.get("position")
self.flags: ChannelFlags = ChannelFlags._from_value(data.get("flags", 0))
self._fill_overwrites(data)
Expand All @@ -2849,10 +2881,6 @@ def type(self) -> ChannelType:
"""The channel's Discord type."""
return ChannelType.category

def is_nsfw(self) -> bool:
"""Checks if the category is NSFW."""
return self.nsfw

@utils.copy_doc(discord.abc.GuildChannel.clone)
async def clone(
self, *, name: str | None = None, reason: str | None = None
Expand All @@ -2865,7 +2893,6 @@ async def edit(
*,
name: str = ...,
position: int = ...,
nsfw: bool = ...,
overwrites: Mapping[Role | Member, PermissionOverwrite] = ...,
reason: str | None = ...,
) -> CategoryChannel | None: ...
Expand Down Expand Up @@ -2893,8 +2920,6 @@ async def edit(self, *, reason=None, **options):
The new category's name.
position: :class:`int`
The new category's position.
nsfw: :class:`bool`
To mark the category as NSFW or not.
reason: Optional[:class:`str`]
The reason for editing this category. Shows up on the audit log.
overwrites: Dict[Union[:class:`Role`, :class:`Member`, :class:`~discord.abc.Snowflake`], :class:`PermissionOverwrite`]
Expand Down Expand Up @@ -3042,6 +3067,12 @@ async def create_forum_channel(self, name: str, **options: Any) -> ForumChannel:
"""
return await self.guild.create_forum_channel(name, category=self, **options)

@utils.deprecated(since="2.7", removed="3.0")
def is_nsfw(self) -> bool:
return False

# TODO: Remove in 3.0


DMC = TypeVar("DMC", bound="DMChannel")

Expand Down
137 changes: 136 additions & 1 deletion discord/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,8 @@ async def create_text_channel(
slowmode_delay: int = MISSING,
nsfw: bool = MISSING,
overwrites: dict[Role | Member, PermissionOverwrite] = MISSING,
default_thread_slowmode_delay: int | None = MISSING,
default_auto_archive_duration: int = MISSING,
) -> TextChannel:
"""|coro|

Expand Down Expand Up @@ -1172,6 +1174,16 @@ async def create_text_channel(
reason: Optional[:class:`str`]
The reason for creating this channel. Shows up on the audit log.

default_thread_slowmode_delay: Optional[:class:`int`]
The initial slowmode delay to set on newly created threads in this channel.

.. versionadded:: 2.7

default_auto_archive_duration: :class:`int`
The default auto archive duration in minutes for threads created in this channel.

.. versionadded:: 2.7

Returns
-------
:class:`TextChannel`
Expand Down Expand Up @@ -1220,6 +1232,12 @@ async def create_text_channel(
if nsfw is not MISSING:
options["nsfw"] = nsfw

if default_thread_slowmode_delay is not MISSING:
options["default_thread_slowmode_delay"] = default_thread_slowmode_delay

if default_auto_archive_duration is not MISSING:
options["default_auto_archive_duration"] = default_auto_archive_duration

data = await self._create_channel(
name,
overwrites=overwrites,
Expand All @@ -1246,6 +1264,8 @@ async def create_voice_channel(
rtc_region: VoiceRegion | None = MISSING,
video_quality_mode: VideoQualityMode = MISSING,
overwrites: dict[Role | Member, PermissionOverwrite] = MISSING,
slowmode_delay: int = MISSING,
nsfw: bool = MISSING,
) -> VoiceChannel:
"""|coro|

Expand Down Expand Up @@ -1280,6 +1300,17 @@ async def create_voice_channel(
reason: Optional[:class:`str`]
The reason for creating this channel. Shows up on the audit log.

slowmode_delay: :class:`int`
Specifies the slowmode rate limit for user in this channel, in seconds.
The maximum value possible is `21600`.

.. versionadded:: 2.7

nsfw: :class:`bool`
To mark the channel as NSFW or not.

.. versionadded:: 2.7

Returns
-------
:class:`VoiceChannel`
Expand Down Expand Up @@ -1310,6 +1341,12 @@ async def create_voice_channel(
if video_quality_mode is not MISSING:
options["video_quality_mode"] = video_quality_mode.value

if slowmode_delay is not MISSING:
options["rate_limit_per_user"] = slowmode_delay

if nsfw is not MISSING:
options["nsfw"] = nsfw

data = await self._create_channel(
name,
overwrites=overwrites,
Expand All @@ -1333,6 +1370,12 @@ async def create_stage_channel(
overwrites: dict[Role | Member, PermissionOverwrite] = MISSING,
category: CategoryChannel | None = None,
reason: str | None = None,
bitrate: int = MISSING,
user_limit: int = MISSING,
rtc_region: VoiceRegion | None = MISSING,
video_quality_mode: VideoQualityMode = MISSING,
slowmode_delay: int = MISSING,
nsfw: bool = MISSING,
) -> StageChannel:
"""|coro|

Expand All @@ -1358,6 +1401,38 @@ async def create_stage_channel(
reason: Optional[:class:`str`]
The reason for creating this channel. Shows up on the audit log.

bitrate: :class:`int`
The channel's preferred audio bitrate in bits per second.

.. versionadded:: 2.7

user_limit: :class:`int`
The channel's limit for number of members that can be in a voice channel.

.. versionadded:: 2.7

rtc_region: Optional[:class:`VoiceRegion`]
The region for the voice channel's voice communication.
A value of ``None`` indicates automatic voice region detection.

.. versionadded:: 2.7

video_quality_mode: :class:`VideoQualityMode`
The camera video quality for the voice channel's participants.

.. versionadded:: 2.7

slowmode_delay: :class:`int`
Specifies the slowmode rate limit for user in this channel, in seconds.
The maximum value possible is `21600`.

.. versionadded:: 2.7

nsfw: :class:`bool`
To mark the channel as NSFW or not.

.. versionadded:: 2.7

Returns
-------
:class:`StageChannel`
Expand All @@ -1379,6 +1454,24 @@ async def create_stage_channel(
if position is not MISSING:
options["position"] = position

if bitrate is not MISSING:
options["bitrate"] = bitrate

if user_limit is not MISSING:
options["user_limit"] = user_limit

if rtc_region is not MISSING:
options["rtc_region"] = None if rtc_region is None else str(rtc_region)

if video_quality_mode is not MISSING:
options["video_quality_mode"] = video_quality_mode.value

if slowmode_delay is not MISSING:
options["rate_limit_per_user"] = slowmode_delay

if nsfw is not MISSING:
options["nsfw"] = nsfw

data = await self._create_channel(
name,
overwrites=overwrites,
Expand All @@ -1405,6 +1498,10 @@ async def create_forum_channel(
nsfw: bool = MISSING,
overwrites: dict[Role | Member, PermissionOverwrite] = MISSING,
default_reaction_emoji: GuildEmoji | int | str = MISSING,
available_tags: list[ForumTag] = MISSING,
default_sort_order: SortOrder | None = MISSING,
default_thread_slowmode_delay: int | None = MISSING,
default_auto_archive_duration: int = MISSING,
) -> ForumChannel:
"""|coro|

Expand Down Expand Up @@ -1453,6 +1550,26 @@ async def create_forum_channel(

.. versionadded:: v2.5

available_tags: List[:class:`ForumTag`]
The set of tags that can be used in a forum channel.

.. versionadded:: 2.7

default_sort_order: Optional[:class:`SortOrder`]
The default sort order type used to order posts in this channel.

.. versionadded:: 2.7

default_thread_slowmode_delay: Optional[:class:`int`]
The initial slowmode delay to set on newly created threads in this channel.

.. versionadded:: 2.7

default_auto_archive_duration: :class:`int`
The default auto archive duration in minutes for threads created in this channel.

.. versionadded:: 2.7

Returns
-------
:class:`ForumChannel`
Expand Down Expand Up @@ -1501,6 +1618,20 @@ async def create_forum_channel(
if nsfw is not MISSING:
options["nsfw"] = nsfw

if available_tags is not MISSING:
options["available_tags"] = [tag.to_dict() for tag in available_tags]

if default_sort_order is not MISSING:
options["default_sort_order"] = (
default_sort_order.value if default_sort_order else None
)

if default_thread_slowmode_delay is not MISSING:
options["default_thread_slowmode_delay"] = default_thread_slowmode_delay

if default_auto_archive_duration is not MISSING:
options["default_auto_archive_duration"] = default_auto_archive_duration

if default_reaction_emoji is not MISSING:
if isinstance(
default_reaction_emoji, _EmojiTag
Expand All @@ -1512,13 +1643,17 @@ async def create_forum_channel(
)
elif isinstance(default_reaction_emoji, str):
default_reaction_emoji = PartialEmoji.from_str(default_reaction_emoji)
elif default_reaction_emoji is None:
pass
else:
raise InvalidArgument(
"default_reaction_emoji must be of type: GuildEmoji | int | str"
"default_reaction_emoji must be of type: GuildEmoji | int | str | None"
)

options["default_reaction_emoji"] = (
default_reaction_emoji._to_forum_reaction_payload()
if default_reaction_emoji
else None
)

data = await self._create_channel(
Expand Down