Skip to content
This repository was archived by the owner on Aug 28, 2019. It is now read-only.

Commit 3ef8f77

Browse files
committed
Add proper nsfw support for vocal guild channels
1 parent 3378435 commit 3ef8f77

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

discord/channel.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,7 @@ class TextChannel(discord.abc.Messageable, discord.abc.GuildChannel, Hashable):
130130
Bots and users with :attr:`~Permissions.manage_channels` or
131131
:attr:`~Permissions.manage_messages` bypass slowmode.
132132
nsfw: :class:`bool`
133-
If the channel is marked as "not safe for work".
134-
135-
.. note::
136-
137-
To check if the channel or the guild of that channel are marked as NSFW, consider :meth:`is_nsfw` instead.
133+
If the channel is marked as "not safe for work" or "age restricted".
138134
default_auto_archive_duration: :class:`int`
139135
The default auto archive duration in minutes for threads created in this channel.
140136
@@ -843,6 +839,7 @@ class VocalGuildChannel(discord.abc.Connectable, discord.abc.GuildChannel, Hasha
843839
'name',
844840
'id',
845841
'guild',
842+
'nsfw',
846843
'bitrate',
847844
'user_limit',
848845
'_state',
@@ -868,6 +865,7 @@ def _get_voice_state_pair(self) -> Tuple[int, int]:
868865
def _update(self, guild: Guild, data: Union[VoiceChannelPayload, StageChannelPayload]) -> None:
869866
self.guild: Guild = guild
870867
self.name: str = data['name']
868+
self.nsfw: bool = data.get('nsfw', False)
871869
self.rtc_region: Optional[str] = data.get('rtc_region')
872870
self.video_quality_mode: VideoQualityMode = try_enum(VideoQualityMode, data.get('video_quality_mode', 1))
873871
self.category_id: Optional[int] = utils._get_as_snowflake(data, 'parent_id')
@@ -881,6 +879,13 @@ def _update(self, guild: Guild, data: Union[VoiceChannelPayload, StageChannelPay
881879
def _sorting_bucket(self) -> int:
882880
return ChannelType.voice.value
883881

882+
def is_nsfw(self) -> bool:
883+
""":class:`bool`: Checks if the channel is NSFW.
884+
885+
.. versionadded:: 2.0
886+
"""
887+
return self.nsfw
888+
884889
@property
885890
def members(self) -> List[Member]:
886891
"""List[:class:`Member`]: Returns all members that are currently inside this voice channel."""
@@ -966,6 +971,10 @@ class VoiceChannel(discord.abc.Messageable, VocalGuildChannel):
966971
The guild the channel belongs to.
967972
id: :class:`int`
968973
The channel ID.
974+
nsfw: :class:`bool`
975+
If the channel is marked as "not safe for work" or "age restricted".
976+
977+
.. versionadded:: 2.0
969978
category_id: Optional[:class:`int`]
970979
The category channel ID this channel belongs to, if applicable.
971980
position: :class:`int`
@@ -1275,6 +1284,7 @@ async def edit(
12751284
self,
12761285
*,
12771286
name: str = ...,
1287+
nsfw: bool = ...,
12781288
bitrate: int = ...,
12791289
user_limit: int = ...,
12801290
position: int = ...,
@@ -1318,6 +1328,8 @@ async def edit(self, *, reason: Optional[str] = None, **options: Any) -> Optiona
13181328
The new channel's name.
13191329
bitrate: :class:`int`
13201330
The new channel's bitrate.
1331+
nsfw: :class:`bool`
1332+
To mark the channel as NSFW or not.
13211333
user_limit: :class:`int`
13221334
The new channel's user limit.
13231335
position: :class:`int`
@@ -1396,6 +1408,10 @@ class StageChannel(VocalGuildChannel):
13961408
The guild the channel belongs to.
13971409
id: :class:`int`
13981410
The channel ID.
1411+
nsfw: :class:`bool`
1412+
If the channel is marked as "not safe for work" or "age restricted".
1413+
1414+
.. versionadded:: 2.0
13991415
topic: Optional[:class:`str`]
14001416
The channel's topic. ``None`` if it isn't set.
14011417
category_id: Optional[:class:`int`]
@@ -1562,6 +1578,7 @@ async def edit(
15621578
self,
15631579
*,
15641580
name: str = ...,
1581+
nsfw: bool = ...,
15651582
position: int = ...,
15661583
sync_permissions: int = ...,
15671584
category: Optional[CategoryChannel] = ...,
@@ -1603,6 +1620,8 @@ async def edit(self, *, reason: Optional[str] = None, **options: Any) -> Optiona
16031620
The new channel's name.
16041621
position: :class:`int`
16051622
The new channel's position.
1623+
nsfw: :class:`bool`
1624+
To mark the channel as NSFW or not.
16061625
sync_permissions: :class:`bool`
16071626
Whether to sync permissions with the channel's new or pre-existing
16081627
category. Defaults to ``False``.

0 commit comments

Comments
 (0)