mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-08-30 06:55:35 +00:00
Change Guild.member_count to Optional[int]
This commit is contained in:
parent
9b65b5ce2e
commit
03687fb616
@ -450,9 +450,7 @@ class Guild(Hashable):
|
|||||||
def _from_data(self, guild: GuildPayload) -> None:
|
def _from_data(self, guild: GuildPayload) -> None:
|
||||||
# according to Stan, this is always available even if the guild is unavailable
|
# according to Stan, this is always available even if the guild is unavailable
|
||||||
# I don't have this guarantee when someone updates the guild.
|
# I don't have this guarantee when someone updates the guild.
|
||||||
member_count = guild.get('member_count', None)
|
self._member_count: Optional[int] = guild.get('member_count', None)
|
||||||
if member_count is not None:
|
|
||||||
self._member_count: int = member_count
|
|
||||||
|
|
||||||
self.name: str = guild.get('name', '')
|
self.name: str = guild.get('name', '')
|
||||||
self.verification_level: VerificationLevel = try_enum(VerificationLevel, guild.get('verification_level'))
|
self.verification_level: VerificationLevel = try_enum(VerificationLevel, guild.get('verification_level'))
|
||||||
@ -514,7 +512,7 @@ class Guild(Hashable):
|
|||||||
self._add_member(member)
|
self._add_member(member)
|
||||||
|
|
||||||
self._sync(guild)
|
self._sync(guild)
|
||||||
self._large: Optional[bool] = None if member_count is None else self._member_count >= 250
|
self._large: Optional[bool] = None if self._member_count is None else self._member_count >= 250
|
||||||
|
|
||||||
self.owner_id: Optional[int] = utils._get_as_snowflake(guild, 'owner_id')
|
self.owner_id: Optional[int] = utils._get_as_snowflake(guild, 'owner_id')
|
||||||
self.afk_channel: Optional[VocalGuildChannel] = self.get_channel(utils._get_as_snowflake(guild, 'afk_channel_id')) # type: ignore
|
self.afk_channel: Optional[VocalGuildChannel] = self.get_channel(utils._get_as_snowflake(guild, 'afk_channel_id')) # type: ignore
|
||||||
@ -966,14 +964,17 @@ class Guild(Hashable):
|
|||||||
return Asset._from_guild_image(self._state, self.id, self._discovery_splash, path='discovery-splashes')
|
return Asset._from_guild_image(self._state, self.id, self._discovery_splash, path='discovery-splashes')
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def member_count(self) -> int:
|
def member_count(self) -> Optional[int]:
|
||||||
""":class:`int`: Returns the true member count regardless of it being loaded fully or not.
|
"""Optional[:class:`int`]: Returns the member count if available.
|
||||||
|
|
||||||
.. warning::
|
.. warning::
|
||||||
|
|
||||||
Due to a Discord limitation, in order for this attribute to remain up-to-date and
|
Due to a Discord limitation, in order for this attribute to remain up-to-date and
|
||||||
accurate, it requires :attr:`Intents.members` to be specified.
|
accurate, it requires :attr:`Intents.members` to be specified.
|
||||||
|
|
||||||
|
.. versionchanged:: 2.0
|
||||||
|
|
||||||
|
Now returns an ``Optional[int]``.
|
||||||
"""
|
"""
|
||||||
return self._member_count
|
return self._member_count
|
||||||
|
|
||||||
|
@ -791,7 +791,7 @@ The return type of the following methods has been changed to an :term:`asynchron
|
|||||||
- :meth:`Guild.fetch_members`
|
- :meth:`Guild.fetch_members`
|
||||||
- :meth:`Reaction.users`
|
- :meth:`Reaction.users`
|
||||||
|
|
||||||
The ``NoMoreItems`` exception was removed as calling :func:`anext` or :meth:`~object.__anext__` on an
|
The ``NoMoreItems`` exception was removed as calling :func:`anext` or :meth:`~object.__anext__` on an
|
||||||
:term:`asynchronous iterator` will now raise :class:`StopAsyncIteration`.
|
:term:`asynchronous iterator` will now raise :class:`StopAsyncIteration`.
|
||||||
|
|
||||||
Removal of ``InvalidArgument`` Exception
|
Removal of ``InvalidArgument`` Exception
|
||||||
@ -918,7 +918,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`.
|
- ``preferred_locale`` in :meth:`Guild.edit` is now of type :class:`Locale`.
|
||||||
|
|
||||||
Attribute Type Changes
|
Attribute Type Changes
|
||||||
------------------------
|
------------------------
|
||||||
@ -929,6 +929,7 @@ The following changes have been made:
|
|||||||
- :meth:`Guild.vanity_invite` may now be ``None``. This has been done to fix an issue with the method returning a broken :class:`Invite` object.
|
- :meth:`Guild.vanity_invite` may now be ``None``. This has been done to fix an issue with the method returning a broken :class:`Invite` object.
|
||||||
- :attr:`Guild.shard_id` is now ``0`` instead of ``None`` if :class:`AutoShardedClient` is not used.
|
- :attr:`Guild.shard_id` is now ``0`` instead of ``None`` if :class:`AutoShardedClient` is not used.
|
||||||
- :attr:`Guild.mfa_level` is now of type :class:`MFALevel`.
|
- :attr:`Guild.mfa_level` is now of type :class:`MFALevel`.
|
||||||
|
- :attr:`Guild.member_count` is now of type Optional[:class:`int`].
|
||||||
- :attr:`AuditLogDiff.mfa_level` is now of type :class:`MFALevel`.
|
- :attr:`AuditLogDiff.mfa_level` is now of type :class:`MFALevel`.
|
||||||
- :attr:`AuditLogDiff.rtc_region` is now of type :class:`str`.
|
- :attr:`AuditLogDiff.rtc_region` is now of type :class:`str`.
|
||||||
- :attr:`StageChannel.rtc_region` is now of type :class:`str`.
|
- :attr:`StageChannel.rtc_region` is now of type :class:`str`.
|
||||||
@ -1171,7 +1172,7 @@ The following attributes have been removed:
|
|||||||
- Use :attr:`ext.commands.CommandOnCooldown.type` instead.
|
- Use :attr:`ext.commands.CommandOnCooldown.type` instead.
|
||||||
|
|
||||||
- ``clean_prefix`` from the :class:`~ext.commands.HelpCommand`
|
- ``clean_prefix`` from the :class:`~ext.commands.HelpCommand`
|
||||||
|
|
||||||
- Use :attr:`ext.commands.Context.clean_prefix` instead.
|
- Use :attr:`ext.commands.Context.clean_prefix` instead.
|
||||||
|
|
||||||
Miscellanous Changes
|
Miscellanous Changes
|
||||||
|
Loading…
x
Reference in New Issue
Block a user