add silent parameter to interaction.delete and webhookmessage.delete

This commit is contained in:
Ethan Olchik 2021-09-28 15:30:20 +01:00
parent 9ad65f6b9e
commit 339bfa62f5
2 changed files with 24 additions and 4 deletions

View File

@ -749,7 +749,7 @@ class InteractionMessage(Message):
allowed_mentions=allowed_mentions, allowed_mentions=allowed_mentions,
) )
async def delete(self, *, delay: Optional[float] = None) -> None: async def delete(self, *, delay: Optional[float] = None, silent: bool = False) -> None:
"""|coro| """|coro|
Deletes the message. Deletes the message.
@ -759,6 +759,12 @@ class InteractionMessage(Message):
delay: Optional[:class:`float`] delay: Optional[:class:`float`]
If provided, the number of seconds to wait before deleting the message. If provided, the number of seconds to wait before deleting the message.
The waiting is done in the background and deletion failures are ignored. The waiting is done in the background and deletion failures are ignored.
silent: :class:`bool`
If silent is set to ``True``, the error will not be raised, it will be ignored.
This defaults to ``False`
.. versionadded:: 2.0
Raises Raises
------ ------
@ -780,4 +786,8 @@ class InteractionMessage(Message):
asyncio.create_task(inner_call()) asyncio.create_task(inner_call())
else: else:
await self._state._interaction.delete_original_message(delay=delay) try:
await self._state._interaction.delete_original_message(delay=delay)
except Exception:
if not silent:
raise

View File

@ -717,7 +717,7 @@ class WebhookMessage(Message):
allowed_mentions=allowed_mentions, allowed_mentions=allowed_mentions,
) )
async def delete(self, *, delay: Optional[float] = None) -> None: async def delete(self, *, delay: Optional[float] = None, silent: bool = False) -> None:
"""|coro| """|coro|
Deletes the message. Deletes the message.
@ -727,6 +727,12 @@ class WebhookMessage(Message):
delay: Optional[:class:`float`] delay: Optional[:class:`float`]
If provided, the number of seconds to wait before deleting the message. If provided, the number of seconds to wait before deleting the message.
The waiting is done in the background and deletion failures are ignored. The waiting is done in the background and deletion failures are ignored.
silent: :class:`bool`
If silent is set to ``True``, the error will not be raised, it will be ignored.
This defaults to ``False`
.. versionadded:: 2.0
Raises Raises
------ ------
@ -748,7 +754,11 @@ class WebhookMessage(Message):
asyncio.create_task(inner_call()) asyncio.create_task(inner_call())
else: else:
await self._state._webhook.delete_message(self.id, delay) try:
await self._state._webhook.delete_message(self.id, delay)
except Exception:
if not silent:
raise
class BaseWebhook(Hashable): class BaseWebhook(Hashable):