From 04145b0ba13866cd457fe8eca5d7ea0259dbdda3 Mon Sep 17 00:00:00 2001 From: Middledot <78228142+Middledot@users.noreply.github.com> Date: Thu, 5 May 2022 11:36:04 -0400 Subject: [PATCH 1/2] Add is_nsfw to voice channels (#1317) * Add is_nsfw to voice channels * fix typing --- discord/channel.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/discord/channel.py b/discord/channel.py index 67ce857661..776da84709 100644 --- a/discord/channel.py +++ b/discord/channel.py @@ -923,7 +923,11 @@ class VoiceChannel(discord.abc.Messageable, VocalGuildChannel): .. versionadded:: 2.0 """ - __slots__ = () + __slots__ = ('nsfw') + + def _update(self, guild: Guild, data: VoiceChannelPayload): + super()._update(guild, data) + self.nsfw: bool = data.get("nsfw", False) def __repr__(self) -> str: attrs = [ @@ -942,6 +946,10 @@ def __repr__(self) -> str: async def _get_channel(self): return self + def is_nsfw(self) -> bool: + """:class:`bool`: Checks if the channel is NSFW.""" + return self.nsfw + @property def last_message(self) -> Optional[Message]: """Fetches the last message from this channel in cache. From 217da1054964e5f052a5ed40a6fba9bb5be6c45b Mon Sep 17 00:00:00 2001 From: Dorukyum <53639936+Dorukyum@users.noreply.github.com> Date: Thu, 5 May 2022 22:38:53 +0300 Subject: [PATCH 2/2] Use Optional[X] instead of Union[X, None] --- discord/guild.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/guild.py b/discord/guild.py index 92c40d13e6..d1cbdb5350 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -1731,7 +1731,7 @@ async def active_threads(self) -> List[Thread]: return threads # TODO: Remove Optional typing here when async iterators are refactored - def fetch_members(self, *, limit: Union[int, None] = 1000, after: Optional[SnowflakeTime] = None) -> MemberIterator: + def fetch_members(self, *, limit: Optional[int] = 1000, after: Optional[SnowflakeTime] = None) -> MemberIterator: """Retrieves an :class:`.AsyncIterator` that enables receiving the guild's members. In order to use this, :meth:`Intents.members` must be enabled.