mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-04-19 15:36:02 +00:00
Add and change Guild attributes and Guild.edit params
This commit is contained in:
parent
4615d6848a
commit
bee2db805d
@ -267,6 +267,10 @@ class Guild(Hashable):
|
||||
Indicates if the guild has widget enabled.
|
||||
|
||||
.. versionadded:: 2.0
|
||||
max_stage_video_users: Optional[:class:`int`]
|
||||
The maximum amount of users in a stage video channel.
|
||||
|
||||
.. versionadded:: 2.3
|
||||
"""
|
||||
|
||||
__slots__ = (
|
||||
@ -315,6 +319,8 @@ class Guild(Hashable):
|
||||
'approximate_member_count',
|
||||
'approximate_presence_count',
|
||||
'premium_progress_bar_enabled',
|
||||
'_safety_alerts_channel_id',
|
||||
'max_stage_video_users',
|
||||
)
|
||||
|
||||
_PREMIUM_GUILD_LIMITS: ClassVar[Dict[Optional[int], _GuildLimit]] = {
|
||||
@ -478,6 +484,7 @@ class Guild(Hashable):
|
||||
self.max_presences: Optional[int] = guild.get('max_presences')
|
||||
self.max_members: Optional[int] = guild.get('max_members')
|
||||
self.max_video_channel_users: Optional[int] = guild.get('max_video_channel_users')
|
||||
self.max_stage_video_users: Optional[int] = guild.get('max_stage_video_channel_users')
|
||||
self.premium_tier: int = guild.get('premium_tier', 0)
|
||||
self.premium_subscription_count: int = guild.get('premium_subscription_count') or 0
|
||||
self.vanity_url_code: Optional[str] = guild.get('vanity_url_code')
|
||||
@ -488,6 +495,7 @@ class Guild(Hashable):
|
||||
self._discovery_splash: Optional[str] = guild.get('discovery_splash')
|
||||
self._rules_channel_id: Optional[int] = utils._get_as_snowflake(guild, 'rules_channel_id')
|
||||
self._public_updates_channel_id: Optional[int] = utils._get_as_snowflake(guild, 'public_updates_channel_id')
|
||||
self._safety_alerts_channel_id: Optional[int] = utils._get_as_snowflake(guild, 'safety_alerts_channel_id')
|
||||
self.nsfw_level: NSFWLevel = try_enum(NSFWLevel, guild.get('nsfw_level', 0))
|
||||
self.mfa_level: MFALevel = try_enum(MFALevel, guild.get('mfa_level', 0))
|
||||
self.approximate_presence_count: Optional[int] = guild.get('approximate_presence_count')
|
||||
@ -801,6 +809,17 @@ class Guild(Hashable):
|
||||
channel_id = self._public_updates_channel_id
|
||||
return channel_id and self._channels.get(channel_id) # type: ignore
|
||||
|
||||
@property
|
||||
def safety_alerts_channel(self) -> Optional[TextChannel]:
|
||||
"""Optional[:class:`TextChannel`]: Return's the guild's channel used for safety alerts, if set.
|
||||
|
||||
For example, this is used for the raid protection setting. The guild must have the ``COMMUNITY`` feature.
|
||||
|
||||
.. versionadded:: 2.3
|
||||
"""
|
||||
channel_id = self._safety_alerts_channel_id
|
||||
return channel_id and self._channels.get(channel_id) # type: ignore
|
||||
|
||||
@property
|
||||
def widget_channel(self) -> Optional[Union[TextChannel, ForumChannel, VoiceChannel, StageChannel]]:
|
||||
"""Optional[Union[:class:`TextChannel`, :class:`ForumChannel`, :class:`VoiceChannel`, :class:`StageChannel`]]: Returns
|
||||
@ -1820,6 +1839,8 @@ class Guild(Hashable):
|
||||
widget_enabled: bool = MISSING,
|
||||
widget_channel: Optional[Snowflake] = MISSING,
|
||||
mfa_level: MFALevel = MISSING,
|
||||
raid_alerts_disabled: bool = MISSING,
|
||||
safety_alerts_channel: TextChannel = MISSING,
|
||||
) -> Guild:
|
||||
r"""|coro|
|
||||
|
||||
@ -1934,6 +1955,18 @@ class Guild(Hashable):
|
||||
reason: Optional[:class:`str`]
|
||||
The reason for editing this guild. Shows up on the audit log.
|
||||
|
||||
raid_alerts_disabled: :class:`bool`
|
||||
Whether the alerts for raid protection should be disabled for the guild.
|
||||
|
||||
.. versionadded:: 2.3
|
||||
|
||||
safety_alerts_channel: Optional[:class:`TextChannel`]
|
||||
The new channel that is used for safety alerts. This is only available to
|
||||
guilds that contain ``COMMUNITY`` in :attr:`Guild.features`. Could be ``None`` for no
|
||||
safety alerts channel.
|
||||
|
||||
.. versionadded:: 2.3
|
||||
|
||||
Raises
|
||||
-------
|
||||
Forbidden
|
||||
@ -1945,9 +1978,9 @@ class Guild(Hashable):
|
||||
PNG or JPG. This is also raised if you are not the owner of the
|
||||
guild and request an ownership transfer.
|
||||
TypeError
|
||||
The type passed to the ``default_notifications``, ``verification_level``,
|
||||
``explicit_content_filter``, ``system_channel_flags``, or ``mfa_level`` parameter was
|
||||
of the incorrect type.
|
||||
The type passed to the ``default_notifications``, ``rules_channel``, ``public_updates_channel``,
|
||||
``safety_alerts_channel`` ``verification_level``, ``explicit_content_filter``,
|
||||
``system_channel_flags``, or ``mfa_level`` parameter was of the incorrect type.
|
||||
|
||||
Returns
|
||||
--------
|
||||
@ -2019,14 +2052,33 @@ class Guild(Hashable):
|
||||
if rules_channel is None:
|
||||
fields['rules_channel_id'] = rules_channel
|
||||
else:
|
||||
if not isinstance(rules_channel, TextChannel):
|
||||
raise TypeError(f'rules_channel must be of type TextChannel not {rules_channel.__class__.__name__}')
|
||||
|
||||
fields['rules_channel_id'] = rules_channel.id
|
||||
|
||||
if public_updates_channel is not MISSING:
|
||||
if public_updates_channel is None:
|
||||
fields['public_updates_channel_id'] = public_updates_channel
|
||||
else:
|
||||
if not isinstance(public_updates_channel, TextChannel):
|
||||
raise TypeError(
|
||||
f'public_updates_channel must be of type TextChannel not {public_updates_channel.__class__.__name__}'
|
||||
)
|
||||
|
||||
fields['public_updates_channel_id'] = public_updates_channel.id
|
||||
|
||||
if safety_alerts_channel is not MISSING:
|
||||
if safety_alerts_channel is None:
|
||||
fields['safety_alerts_channel_id'] = safety_alerts_channel
|
||||
else:
|
||||
if not isinstance(safety_alerts_channel, TextChannel):
|
||||
raise TypeError(
|
||||
f'safety_alerts_channel must be of type TextChannel not {safety_alerts_channel.__class__.__name__}'
|
||||
)
|
||||
|
||||
fields['safety_alerts_channel_id'] = safety_alerts_channel.id
|
||||
|
||||
if owner is not MISSING:
|
||||
if self.owner_id != self._state.self_id:
|
||||
raise ValueError('To transfer ownership you must be the owner of the guild.')
|
||||
@ -2051,7 +2103,7 @@ class Guild(Hashable):
|
||||
|
||||
fields['system_channel_flags'] = system_channel_flags.value
|
||||
|
||||
if any(feat is not MISSING for feat in (community, discoverable, invites_disabled)):
|
||||
if any(feat is not MISSING for feat in (community, discoverable, invites_disabled, raid_alerts_disabled)):
|
||||
features = set(self.features)
|
||||
|
||||
if community is not MISSING:
|
||||
@ -2077,6 +2129,12 @@ class Guild(Hashable):
|
||||
else:
|
||||
features.discard('INVITES_DISABLED')
|
||||
|
||||
if raid_alerts_disabled is not MISSING:
|
||||
if raid_alerts_disabled:
|
||||
features.add('RAID_ALERTS_DISABLED')
|
||||
else:
|
||||
features.discard('RAID_ALERTS_DISABLED')
|
||||
|
||||
fields['features'] = list(features)
|
||||
|
||||
if premium_progress_bar_enabled is not MISSING:
|
||||
|
@ -1426,6 +1426,7 @@ class HTTPClient:
|
||||
'public_updates_channel_id',
|
||||
'preferred_locale',
|
||||
'premium_progress_bar_enabled',
|
||||
'safety_alerts_channel_id',
|
||||
)
|
||||
|
||||
payload = {k: v for k, v in fields.items() if k in valid_keys}
|
||||
|
@ -84,6 +84,7 @@ GuildFeature = Literal[
|
||||
'VERIFIED',
|
||||
'VIP_REGIONS',
|
||||
'WELCOME_SCREEN_ENABLED',
|
||||
'RAID_ALERTS_DISABLED',
|
||||
]
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user