From 0cca3ca5c65c8a671cfd23d124ee0b97e61d2272 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Fri, 21 Jun 2019 00:39:52 -0400 Subject: [PATCH] Add support for suppressing embeds. --- discord/http.py | 6 ++++++ discord/message.py | 25 +++++++++++++++++++------ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/discord/http.py b/discord/http.py index 79c03db2e..84bd45da8 100644 --- a/discord/http.py +++ b/discord/http.py @@ -374,6 +374,12 @@ class HTTPClient: r = Route('PATCH', '/channels/{channel_id}/messages/{message_id}', channel_id=channel_id, message_id=message_id) return self.request(r, json=fields) + def suppress_message_embeds(self, channel_id, message_id, *, suppress): + payload = { 'suppress': suppress } + r = Route('POST', '/channels/{channel_id}/messages/{message_id}/suppress-embeds', + channel_id=channel_id, message_id=message_id) + return self.request(r, json=payload) + def add_reaction(self, channel_id, message_id, emoji): r = Route('PUT', '/channels/{channel_id}/messages/{message_id}/reactions/{emoji}/@me', channel_id=channel_id, message_id=message_id, emoji=emoji) diff --git a/discord/message.py b/discord/message.py index 74509baee..e2812c7d3 100644 --- a/discord/message.py +++ b/discord/message.py @@ -711,6 +711,11 @@ class Message: embed: Optional[:class:`Embed`] The new embed to replace the original with. Could be ``None`` to remove the embed. + suppress: :class:`bool` + Whether to suppress embeds for the message. This removes + all the embeds if set to ``True``. If set to ``False`` + this brings the embeds back if they were suppressed. + Using this parameter requires :attr:`~.Permissions.manage_messages`. delete_after: Optional[:class:`float`] If provided, the number of seconds to wait in the background before deleting the message we just edited. If the deletion fails, @@ -720,6 +725,9 @@ class Message: ------- HTTPException Editing the message failed. + Forbidden + Tried to suppress a message without permissions or + edited a message's content or embed that isn't yours. """ try: @@ -738,16 +746,21 @@ class Message: if embed is not None: fields['embed'] = embed.to_dict() - data = await self._state.http.edit_message(self.channel.id, self.id, **fields) - self._update(data) - try: - delete_after = fields['delete_after'] + suppress = fields.pop('suppress') except KeyError: pass else: - if delete_after is not None: - await self.delete(delay=delete_after) + await self._state.http.suppress_message_embeds(self.channel.id, self.id, suppress=suppress) + + delete_after = fields.pop('delete_after', None) + + if fields: + data = await self._state.http.edit_message(self.channel.id, self.id, **fields) + self._update(data) + + if delete_after is not None: + await self.delete(delay=delete_after) async def pin(self): """|coro|