Improve generic duck type programming with PartialMessageable

This adds jump_url, permissions_for, and created_at. Luckily, most
cases of this type being constructed already have the guild_id at
creation time.
This commit is contained in:
Rapptz
2022-05-03 10:49:52 -04:00
parent e9c7c09ebf
commit 8699d2139a
8 changed files with 59 additions and 11 deletions

View File

@@ -807,7 +807,9 @@ class Client:
"""
return self._connection.get_channel(id) # type: ignore # The cache contains all channel types
def get_partial_messageable(self, id: int, *, type: Optional[ChannelType] = None) -> PartialMessageable:
def get_partial_messageable(
self, id: int, *, guild_id: Optional[int] = None, type: Optional[ChannelType] = None
) -> PartialMessageable:
"""Returns a partial messageable with the given channel ID.
This is useful if you have a channel_id but don't want to do an API call
@@ -819,6 +821,11 @@ class Client:
-----------
id: :class:`int`
The channel ID to create a partial messageable for.
guild_id: Optional[:class:`int`]
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.
type: Optional[:class:`.ChannelType`]
The underlying channel type for the partial messageable.
@@ -827,7 +834,7 @@ class Client:
:class:`.PartialMessageable`
The partial messageable
"""
return PartialMessageable(state=self._connection, id=id, type=type)
return PartialMessageable(state=self._connection, id=id, guild_id=guild_id, type=type)
def get_stage_instance(self, id: int, /) -> Optional[StageInstance]:
"""Returns a stage instance with the given stage channel ID.