Skip to content

docs: Improve docstrings and attribute documentation #2754

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

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from 11 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ These changes are available on the `master` branch, but have not yet been releas
([#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)
- Fixed missing docstrings and parameters for channels, allow creating channels with
None as default reaction
([#2754])(https://github.com/Pycord-Development/pycord/pull/2754)

### Changed

Expand Down
51 changes: 51 additions & 0 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.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
To mark the channel as NSFW or not.
Whether the channel is marked as NSFW or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

for the nsfw docs, i copy them from their class to keep them similar

Copy link
Member

Choose a reason for hiding this comment

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

Yeah but here it's not for editing the channel it's an attribute


.. 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: int = ...,
reason: str | None = ...,
) -> VoiceChannel | None: ...

Expand Down Expand Up @@ -2092,6 +2100,17 @@ 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`.

.. versionadded:: 2.7

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

.. versionadded:: 2.7

Returns
-------
Optional[:class:`.VoiceChannel`]
Expand Down Expand Up @@ -2250,6 +2269,17 @@ 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`.

.. versionadded:: 2.7

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

.. versionadded:: 2.7
"""

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

.. versionadded:: 2.0

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

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
-------
Optional[:class:`.StageChannel`]
Expand Down
141 changes: 140 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 All @@ -1542,6 +1677,7 @@ async def create_category(
overwrites: dict[Role | Member, PermissionOverwrite] = MISSING,
reason: str | None = None,
position: int = MISSING,
nsfw: bool = MISSING,
Copy link
Member

Choose a reason for hiding this comment

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

What happens really when a category is nsfw ? Is that inherited to the category's channels ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no idea, i guess yes

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

@Lumabots see above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Screenshot 2025-04-10 at 10 52 54 @Paillat-dev @plun1331 since it return still an nsfw should i let it inside or not ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

even if i dont think it change anything so i'll remove it

) -> CategoryChannel:
"""|coro|

Expand Down Expand Up @@ -1570,6 +1706,9 @@ async def create_category(
if position is not MISSING:
options["position"] = position

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

data = await self._create_channel(
name,
overwrites=overwrites,
Expand Down