mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-06-08 04:38:42 +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."""
|
""":class:`ChannelType`: The channel's Discord type."""
|
||||||
return ChannelType.private
|
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
|
@property
|
||||||
def jump_url(self) -> str:
|
def jump_url(self) -> str:
|
||||||
""":class:`str`: Returns a URL that allows the client to jump to the channel.
|
""":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."""
|
""":class:`ChannelType`: The channel's Discord type."""
|
||||||
return ChannelType.group
|
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
|
@property
|
||||||
def icon(self) -> Optional[Asset]:
|
def icon(self) -> Optional[Asset]:
|
||||||
"""Optional[:class:`Asset`]: Returns the channel's icon asset if available."""
|
"""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:
|
async def _get_channel(self) -> PartialMessageable:
|
||||||
return self
|
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
|
@property
|
||||||
def jump_url(self) -> str:
|
def jump_url(self) -> str:
|
||||||
""":class:`str`: Returns a URL that allows the client to jump to the channel."""
|
""":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.
|
The optional guild ID to create a partial messageable for.
|
||||||
|
|
||||||
This is not required to actually send messages, but it does allow the
|
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`]
|
type: Optional[:class:`.ChannelType`]
|
||||||
The underlying channel type for the partial messageable.
|
The underlying channel type for the partial messageable.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user