mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-09-04 08:56:19 +00:00
Add Widget.presence_count attribute and fix Widget types
This commit is contained in:
@ -231,7 +231,7 @@ class Widget:
|
||||
channels: List[:class:`WidgetChannel`]
|
||||
The accessible voice channels in the guild.
|
||||
members: List[:class:`Member`]
|
||||
The online members in the server. Offline members
|
||||
The online members in the guild. Offline members
|
||||
do not appear in the widget.
|
||||
|
||||
.. note::
|
||||
@ -240,10 +240,15 @@ class Widget:
|
||||
the users will be "anonymized" with linear IDs and discriminator
|
||||
information being incorrect. Likewise, the number of members
|
||||
retrieved is capped.
|
||||
presence_count: :class:`int`
|
||||
The approximate number of online members in the guild.
|
||||
Offline members are not included in this count.
|
||||
|
||||
.. versionadded:: 2.0
|
||||
|
||||
"""
|
||||
|
||||
__slots__ = ('_state', 'channels', '_invite', 'id', 'members', 'name')
|
||||
__slots__ = ('_state', 'channels', '_invite', 'id', 'members', 'name', 'presence_count')
|
||||
|
||||
def __init__(self, *, state: ConnectionState, data: WidgetPayload) -> None:
|
||||
self._state = state
|
||||
@ -268,6 +273,8 @@ class Widget:
|
||||
|
||||
self.members.append(WidgetMember(state=self._state, data=member, connected_channel=connected_channel))
|
||||
|
||||
self.presence_count: int = data['presence_count']
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.json_url
|
||||
|
||||
@ -290,11 +297,11 @@ class Widget:
|
||||
return f"https://discord.com/api/guilds/{self.id}/widget.json"
|
||||
|
||||
@property
|
||||
def invite_url(self) -> str:
|
||||
def invite_url(self) -> Optional[str]:
|
||||
"""Optional[:class:`str`]: The invite URL for the guild, if available."""
|
||||
return self._invite
|
||||
|
||||
async def fetch_invite(self, *, with_counts: bool = True) -> Invite:
|
||||
async def fetch_invite(self, *, with_counts: bool = True) -> Optional[Invite]:
|
||||
"""|coro|
|
||||
|
||||
Retrieves an :class:`Invite` from the widget's invite URL.
|
||||
@ -310,9 +317,11 @@ class Widget:
|
||||
|
||||
Returns
|
||||
--------
|
||||
:class:`Invite`
|
||||
The invite from the widget's invite URL.
|
||||
Optional[:class:`Invite`]
|
||||
The invite from the widget's invite URL, if available.
|
||||
"""
|
||||
resolved = resolve_invite(self._invite)
|
||||
data = await self._state.http.get_invite(resolved.code, with_counts=with_counts)
|
||||
return Invite.from_incomplete(state=self._state, data=data)
|
||||
if self._invite:
|
||||
resolved = resolve_invite(self._invite)
|
||||
data = await self._state.http.get_invite(resolved.code, with_counts=with_counts)
|
||||
return Invite.from_incomplete(state=self._state, data=data)
|
||||
return None
|
||||
|
Reference in New Issue
Block a user