Skip to content

Commit

Permalink
Add Guild.nsfw_level
Browse files Browse the repository at this point in the history
  • Loading branch information
NCPlayz authored Jun 8, 2021
1 parent dd727fb commit a7ae2eb
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
7 changes: 7 additions & 0 deletions discord/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
'StagePrivacyLevel',
'InteractionType',
'InteractionResponseType',
'NSFWLevel',
)

def _create_value_cls(name):
Expand Down Expand Up @@ -488,6 +489,12 @@ class StagePrivacyLevel(Enum):
closed = 2
guild_only = 2

class NSFWLevel(Enum):
default = 0
explicit = 1
safe = 2
age_restricted = 3

T = TypeVar('T')

def create_unknown_value(cls: Type[T], val: Any) -> T:
Expand Down
11 changes: 5 additions & 6 deletions discord/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from .colour import Colour
from .errors import InvalidArgument, ClientException
from .channel import *
from .enums import AuditLogAction, VideoQualityMode, VoiceRegion, ChannelType, try_enum, VerificationLevel, ContentFilter, NotificationLevel
from .enums import AuditLogAction, VideoQualityMode, VoiceRegion, ChannelType, try_enum, VerificationLevel, ContentFilter, NotificationLevel, NSFWLevel
from .mixins import Hashable
from .user import User
from .invite import Invite
Expand Down Expand Up @@ -167,9 +167,8 @@ class Guild(Hashable):
preferred_locale: Optional[:class:`str`]
The preferred locale for the guild. Used when filtering Server Discovery
results to a specific language.
nsfw: :class:`bool`
If the guild is marked as "not safe for work".
nsfw_level: :class:`NSFWLevel`
The guild's NSFW level.
.. versionadded:: 2.0
"""
Expand All @@ -183,7 +182,7 @@ class Guild(Hashable):
'description', 'max_presences', 'max_members', 'max_video_channel_users',
'premium_tier', 'premium_subscription_count', '_system_channel_flags',
'preferred_locale', '_discovery_splash', '_rules_channel_id',
'_public_updates_channel_id', '_stage_instances', 'nsfw')
'_public_updates_channel_id', '_stage_instances', 'nsfw_level')

_PREMIUM_GUILD_LIMITS = {
None: _GuildLimit(emoji=50, bitrate=96e3, filesize=8388608),
Expand Down Expand Up @@ -318,7 +317,7 @@ def _from_data(self, guild):
self._discovery_splash = guild.get('discovery_splash')
self._rules_channel_id = utils._get_as_snowflake(guild, 'rules_channel_id')
self._public_updates_channel_id = utils._get_as_snowflake(guild, 'public_updates_channel_id')
self.nsfw = guild.get('nsfw', False)
self.nsfw_level = try_enum(NSFWLevel, guild.get('nsfw_level', 0))

self._stage_instances = {}
for s in guild.get('stage_instances', []):
Expand Down
3 changes: 2 additions & 1 deletion discord/types/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class _GuildOptional(TypedDict, total=False):
ExplicitContentFilterLevel = Literal[0, 1, 2]
MFALevel = Literal[0, 1]
VerificationLevel = Literal[0, 1, 2, 3, 4]
NSFWLevel = Literal[0, 1, 2, 3]
PremiumTier = Literal[0, 1, 2, 3]
GuildFeature = Literal[
'INVITE_SPLASH',
Expand Down Expand Up @@ -119,7 +120,7 @@ class Guild(_BaseGuildPreview, _GuildOptional):
explicit_content_filter: ExplicitContentFilterLevel
roles: List[Role]
mfa_level: MFALevel
nsfw: bool
nsfw_level: NSFWLevel
application_id: Optional[Snowflake]
system_channel_id: Optional[Snowflake]
system_channel_flags: int
Expand Down
22 changes: 22 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2197,6 +2197,28 @@ of :class:`enum.Enum`.

Alias for :attr:`.closed`

.. class:: NSFWLevel

Represents the NSFW level of a guild.

.. versionadded:: 2.0

.. attribute:: default

The guild has not been categorised yet.

.. attribute:: explicit

The guild contains NSFW content.

.. attribute:: safe

The guild does not contain any NSFW content.

.. attribute:: age_restricted

The guild may contain NSFW content.

Async Iterator
----------------

Expand Down

0 comments on commit a7ae2eb

Please sign in to comment.