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 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ 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 parameters for channels And allow creating channels with None as default
reaction ([#2754])(https://github.com/Pycord-Development/pycord/pull/2754)

### Changed

Expand Down
59 changes: 47 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.
Copy link
Contributor

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
Contributor

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,22 @@ 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

Returns
-------
Optional[:class:`.StageChannel`]
Expand Down Expand Up @@ -2790,12 +2836,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 +2867,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 +2878,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 +2891,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 +2903,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 +2930,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
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
Loading