mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-04-20 07:54:36 +00:00
Add guild property to DMChannel, GroupChannel, and PartialMessageable
This improves generic duck typing programming by allowing narrowing the types by just checking for a None guild attribute.
This commit is contained in:
parent
8699d2139a
commit
c22b6dc2cd
@ -2353,6 +2353,16 @@ class DMChannel(discord.abc.Messageable, Hashable):
|
||||
""":class:`ChannelType`: The channel's Discord type."""
|
||||
return ChannelType.private
|
||||
|
||||
@property
|
||||
def guild(self) -> Optional[Guild]:
|
||||
"""Optional[:class:`Guild`]: The guild this DM channel belongs to. Always ``None``.
|
||||
|
||||
This is mainly provided for compatibility purposes in duck typing.
|
||||
|
||||
.. versionadded:: 2.0
|
||||
"""
|
||||
return None
|
||||
|
||||
@property
|
||||
def jump_url(self) -> str:
|
||||
""":class:`str`: Returns a URL that allows the client to jump to the channel.
|
||||
@ -2507,6 +2517,16 @@ class GroupChannel(discord.abc.Messageable, Hashable):
|
||||
""":class:`ChannelType`: The channel's Discord type."""
|
||||
return ChannelType.group
|
||||
|
||||
@property
|
||||
def guild(self) -> Optional[Guild]:
|
||||
"""Optional[:class:`Guild`]: The guild this group channel belongs to. Always ``None``.
|
||||
|
||||
This is mainly provided for compatibility purposes in duck typing.
|
||||
|
||||
.. versionadded:: 2.0
|
||||
"""
|
||||
return None
|
||||
|
||||
@property
|
||||
def icon(self) -> Optional[Asset]:
|
||||
"""Optional[:class:`Asset`]: Returns the channel's icon asset if available."""
|
||||
@ -2629,6 +2649,11 @@ class PartialMessageable(discord.abc.Messageable, Hashable):
|
||||
async def _get_channel(self) -> PartialMessageable:
|
||||
return self
|
||||
|
||||
@property
|
||||
def guild(self) -> Optional[Guild]:
|
||||
"""Optional[:class:`Guild`]: The guild this partial messageable is in."""
|
||||
return self._state._get_guild(self.guild_id)
|
||||
|
||||
@property
|
||||
def jump_url(self) -> str:
|
||||
""":class:`str`: Returns a URL that allows the client to jump to the channel."""
|
||||
|
@ -825,7 +825,8 @@ class Client:
|
||||
The optional guild ID to create a partial messageable for.
|
||||
|
||||
This is not required to actually send messages, but it does allow the
|
||||
:meth:`PartialMessageable.jump_url` property to form a well formed URL.
|
||||
:meth:`PartialMessageable.jump_url` and :attr:`PartialMessageable.guild`
|
||||
properties to function properly.
|
||||
type: Optional[:class:`.ChannelType`]
|
||||
The underlying channel type for the partial messageable.
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user