Change Guild.preferred_locale to use the Locale enum

This commit is contained in:
Stocker 2022-03-05 23:30:51 -05:00 committed by GitHub
parent 85b6175137
commit 07a1311bf4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 6 deletions

View File

@ -68,6 +68,7 @@ from .enums import (
NotificationLevel, NotificationLevel,
NSFWLevel, NSFWLevel,
MFALevel, MFALevel,
Locale,
) )
from .mixins import Hashable from .mixins import Hashable
from .user import User from .user import User
@ -243,9 +244,12 @@ class Guild(Hashable):
The number goes from 0 to 3 inclusive. The number goes from 0 to 3 inclusive.
premium_subscription_count: :class:`int` premium_subscription_count: :class:`int`
The number of "boosts" this guild currently has. The number of "boosts" this guild currently has.
preferred_locale: Optional[:class:`str`] preferred_locale: :class:`Locale`
The preferred locale for the guild. Used when filtering Server Discovery The preferred locale for the guild. Used when filtering Server Discovery
results to a specific language. results to a specific language.
.. versionchanged:: 2.0
This field is now an enum instead of a :class:`str`.
nsfw_level: :class:`NSFWLevel` nsfw_level: :class:`NSFWLevel`
The guild's NSFW level. The guild's NSFW level.
@ -471,7 +475,7 @@ class Guild(Hashable):
self.premium_tier: int = guild.get('premium_tier', 0) self.premium_tier: int = guild.get('premium_tier', 0)
self.premium_subscription_count: int = guild.get('premium_subscription_count') or 0 self.premium_subscription_count: int = guild.get('premium_subscription_count') or 0
self._system_channel_flags: int = guild.get('system_channel_flags', 0) self._system_channel_flags: int = guild.get('system_channel_flags', 0)
self.preferred_locale: Optional[str] = guild.get('preferred_locale') self.preferred_locale: Locale = try_enum(Locale, guild.get('preferred_locale', 'en-US'))
self._discovery_splash: Optional[str] = guild.get('discovery_splash') self._discovery_splash: Optional[str] = guild.get('discovery_splash')
self._rules_channel_id: Optional[int] = utils._get_as_snowflake(guild, 'rules_channel_id') 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._public_updates_channel_id: Optional[int] = utils._get_as_snowflake(guild, 'public_updates_channel_id')
@ -1540,7 +1544,7 @@ class Guild(Hashable):
vanity_code: str = MISSING, vanity_code: str = MISSING,
system_channel: Optional[TextChannel] = MISSING, system_channel: Optional[TextChannel] = MISSING,
system_channel_flags: SystemChannelFlags = MISSING, system_channel_flags: SystemChannelFlags = MISSING,
preferred_locale: str = MISSING, preferred_locale: Locale = MISSING,
rules_channel: Optional[TextChannel] = MISSING, rules_channel: Optional[TextChannel] = MISSING,
public_updates_channel: Optional[TextChannel] = MISSING, public_updates_channel: Optional[TextChannel] = MISSING,
) -> Guild: ) -> Guild:
@ -1567,6 +1571,9 @@ class Guild(Hashable):
This function no-longer raises ``InvalidArgument`` instead raising This function no-longer raises ``InvalidArgument`` instead raising
:exc:`ValueError` or :exc:`TypeError` in various cases. :exc:`ValueError` or :exc:`TypeError` in various cases.
.. versionchanged:: 2.0
The ``preferred_locale`` keyword parameter now accepts an enum instead of :class:`str`.
Parameters Parameters
---------- ----------
name: :class:`str` name: :class:`str`
@ -1614,9 +1621,8 @@ class Guild(Hashable):
The new channel that is used for the system channel. Could be ``None`` for no system channel. The new channel that is used for the system channel. Could be ``None`` for no system channel.
system_channel_flags: :class:`SystemChannelFlags` system_channel_flags: :class:`SystemChannelFlags`
The new system channel settings to use with the new system channel. The new system channel settings to use with the new system channel.
preferred_locale: :class:`str` preferred_locale: :class:`Locale`
The new preferred locale for the guild. Used as the primary language in the guild. The new preferred locale for the guild. Used as the primary language in the guild.
If set, this must be an ISO 639 code, e.g. ``en-US`` or ``ja`` or ``zh-CN``.
rules_channel: Optional[:class:`TextChannel`] rules_channel: Optional[:class:`TextChannel`]
The new channel that is used for rules. This is only available to The new channel that is used for rules. This is only available to
guilds that contain ``PUBLIC`` in :attr:`Guild.features`. Could be ``None`` for no rules guilds that contain ``PUBLIC`` in :attr:`Guild.features`. Could be ``None`` for no rules
@ -1663,7 +1669,7 @@ class Guild(Hashable):
fields['description'] = description fields['description'] = description
if preferred_locale is not MISSING: if preferred_locale is not MISSING:
fields['preferred_locale'] = preferred_locale fields['preferred_locale'] = str(preferred_locale)
if afk_timeout is not MISSING: if afk_timeout is not MISSING:
fields['afk_timeout'] = afk_timeout fields['afk_timeout'] = afk_timeout

View File

@ -915,6 +915,7 @@ Allowed types for the following parameters have been changed:
- ``rtc_region`` in :meth:`Guild.create_voice_channel` is now of type Optional[:class:`str`]. - ``rtc_region`` in :meth:`Guild.create_voice_channel` is now of type Optional[:class:`str`].
- ``rtc_region`` in :meth:`StageChannel.edit` is now of type Optional[:class:`str`]. - ``rtc_region`` in :meth:`StageChannel.edit` is now of type Optional[:class:`str`].
- ``rtc_region`` in :meth:`VoiceChannel.edit` is now of type Optional[:class:`str`]. - ``rtc_region`` in :meth:`VoiceChannel.edit` is now of type Optional[:class:`str`].
- ``preferred_locale`` in :meth`Guild.edit` is now of type :class:`Locale`.
Attribute Type Changes Attribute Type Changes
------------------------ ------------------------
@ -948,6 +949,7 @@ The following changes have been made:
- :attr:`AuditLogEntry.target` may now be a :class:`PartialMessageable`. - :attr:`AuditLogEntry.target` may now be a :class:`PartialMessageable`.
- :attr:`PartialMessage.channel` may now be a :class:`PartialMessageable`. - :attr:`PartialMessage.channel` may now be a :class:`PartialMessageable`.
- :attr:`Guild.preferred_locale` is now of type :class:`Locale`.
Removals Removals
---------- ----------