diff --git a/discord/channel.py b/discord/channel.py index f2dbdffab..98ec3a660 100644 --- a/discord/channel.py +++ b/discord/channel.py @@ -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.""" diff --git a/discord/client.py b/discord/client.py index c579ded55..4fe157a16 100644 --- a/discord/client.py +++ b/discord/client.py @@ -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.