From ad4e85f9957dd4ffde479551e8997bee4aab642f Mon Sep 17 00:00:00 2001 From: vi <8530778+shiftinv@users.noreply.github.com> Date: Wed, 25 Dec 2024 17:39:41 +0100 Subject: [PATCH] feat(channel): add `GroupChannel.get_partial_message` (#1256) --- changelog/1256.feature.rst | 1 + disnake/channel.py | 22 ++++++++++++++++++++++ disnake/message.py | 4 +++- 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 changelog/1256.feature.rst diff --git a/changelog/1256.feature.rst b/changelog/1256.feature.rst new file mode 100644 index 0000000000..56996d6e38 --- /dev/null +++ b/changelog/1256.feature.rst @@ -0,0 +1 @@ +Add :meth:`GroupChannel.get_partial_message`. diff --git a/disnake/channel.py b/disnake/channel.py index 90d5792a39..55b35562cd 100644 --- a/disnake/channel.py +++ b/disnake/channel.py @@ -4968,6 +4968,28 @@ def permissions_for( return base + def get_partial_message(self, message_id: int, /) -> PartialMessage: + """Creates a :class:`PartialMessage` from the given message ID. + + This is useful if you want to work with a message and only have its ID without + doing an unnecessary API call. + + .. versionadded:: 2.10 + + Parameters + ---------- + message_id: :class:`int` + The message ID to create a partial message for. + + Returns + ------- + :class:`PartialMessage` + The partial message object. + """ + from .message import PartialMessage + + return PartialMessage(channel=self, id=message_id) + async def leave(self) -> None: """|coro| diff --git a/disnake/message.py b/disnake/message.py index efe965ae13..e4cb7ee0e6 100644 --- a/disnake/message.py +++ b/disnake/message.py @@ -2511,6 +2511,7 @@ class PartialMessage(Hashable): - :meth:`StageChannel.get_partial_message` - :meth:`Thread.get_partial_message` - :meth:`DMChannel.get_partial_message` + - :meth:`GroupChannel.get_partial_message` - :meth:`PartialMessageable.get_partial_message` Note that this class is trimmed down and has no rich attributes. @@ -2560,6 +2561,7 @@ def __init__(self, *, channel: MessageableChannel, id: int) -> None: ChannelType.text, ChannelType.news, ChannelType.private, + ChannelType.group, ChannelType.news_thread, ChannelType.public_thread, ChannelType.private_thread, @@ -2567,7 +2569,7 @@ def __init__(self, *, channel: MessageableChannel, id: int) -> None: ChannelType.stage_voice, ): raise TypeError( - f"Expected TextChannel, VoiceChannel, DMChannel, StageChannel, Thread, or PartialMessageable " + f"Expected TextChannel, VoiceChannel, StageChannel, Thread, DMChannel, GroupChannel, or PartialMessageable " f"with a valid type, not {type(channel)!r} (type: {channel.type!r})" )