aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2021-05-31 00:17:35 -0400
committerRapptz <[email protected]>2021-05-31 00:17:35 -0400
commit8dafe4f54497ff19c8b610ebef93675ce6b3c264 (patch)
tree11c2adb4b2abee8f2a713d345a900dc66434736f
parentAdd View.is_finished() to query listening state (diff)
downloaddiscord.py-8dafe4f54497ff19c8b610ebef93675ce6b3c264.tar.xz
discord.py-8dafe4f54497ff19c8b610ebef93675ce6b3c264.zip
Add support for editing in views in PartialMessage
-rw-r--r--discord/message.py21
1 files changed, 20 insertions, 1 deletions
diff --git a/discord/message.py b/discord/message.py
index 5afbff71..41d8e21c 100644
--- a/discord/message.py
+++ b/discord/message.py
@@ -1620,6 +1620,11 @@ class PartialMessage(Hashable):
to the object, otherwise it uses the attributes set in :attr:`~discord.Client.allowed_mentions`.
If no object is passed at all then the defaults given by :attr:`~discord.Client.allowed_mentions`
are used instead.
+ view: Optional[:class:`~discord.ui.View`]
+ The updated view to update this message with. If ``None`` is passed then
+ the view is removed.
+
+ .. versionadded:: 2.0
Raises
-------
@@ -1676,6 +1681,17 @@ class PartialMessage(Hashable):
allowed_mentions = allowed_mentions.to_dict()
fields['allowed_mentions'] = allowed_mentions
+ try:
+ view = fields.pop('view')
+ except KeyError:
+ # To check for the view afterwards
+ view = None
+ else:
+ if view:
+ fields['components'] = view.to_components()
+ else:
+ fields['components'] = []
+
if fields:
data = await self._state.http.edit_message(self.channel.id, self.id, **fields)
@@ -1683,4 +1699,7 @@ class PartialMessage(Hashable):
await self.delete(delay=delete_after) # type: ignore
if fields:
- return self._state.create_message(channel=self.channel, data=data) # type: ignore
+ msg = self._state.create_message(channel=self.channel, data=data) # type: ignore
+ if view:
+ self._state.store_view(view, self.id)
+ return msg