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

@ -244,7 +244,9 @@ class Context(discord.abc.Messageable, Generic[BotT]):
if interaction.channel_id is None:
raise RuntimeError('interaction channel ID is null, this is probably a Discord bug')
channel = interaction.channel or PartialMessageable(state=interaction._state, id=interaction.channel_id)
channel = interaction.channel or PartialMessageable(
state=interaction._state, guild_id=interaction.guild_id, id=interaction.channel_id
)
message = Message(state=interaction._state, channel=channel, data=synthetic_payload) # type: ignore
message.author = interaction.user
message.attachments = [a for _, a in interaction.namespace if isinstance(a, Attachment)]