Browse Source

Add support for suppressing embeds.

pull/2255/head
Rapptz 6 years ago
parent
commit
0cca3ca5c6
  1. 6
      discord/http.py
  2. 25
      discord/message.py

6
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) r = Route('PATCH', '/channels/{channel_id}/messages/{message_id}', channel_id=channel_id, message_id=message_id)
return self.request(r, json=fields) 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): def add_reaction(self, channel_id, message_id, emoji):
r = Route('PUT', '/channels/{channel_id}/messages/{message_id}/reactions/{emoji}/@me', r = Route('PUT', '/channels/{channel_id}/messages/{message_id}/reactions/{emoji}/@me',
channel_id=channel_id, message_id=message_id, emoji=emoji) channel_id=channel_id, message_id=message_id, emoji=emoji)

25
discord/message.py

@ -711,6 +711,11 @@ class Message:
embed: Optional[:class:`Embed`] embed: Optional[:class:`Embed`]
The new embed to replace the original with. The new embed to replace the original with.
Could be ``None`` to remove the embed. 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`] delete_after: Optional[:class:`float`]
If provided, the number of seconds to wait in the background If provided, the number of seconds to wait in the background
before deleting the message we just edited. If the deletion fails, before deleting the message we just edited. If the deletion fails,
@ -720,6 +725,9 @@ class Message:
------- -------
HTTPException HTTPException
Editing the message failed. 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: try:
@ -738,16 +746,21 @@ class Message:
if embed is not None: if embed is not None:
fields['embed'] = embed.to_dict() fields['embed'] = embed.to_dict()
data = await self._state.http.edit_message(self.channel.id, self.id, **fields)
self._update(data)
try: try:
delete_after = fields['delete_after'] suppress = fields.pop('suppress')
except KeyError: except KeyError:
pass pass
else: else:
if delete_after is not None: await self._state.http.suppress_message_embeds(self.channel.id, self.id, suppress=suppress)
await self.delete(delay=delete_after)
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): async def pin(self):
"""|coro| """|coro|

Loading…
Cancel
Save