diff --git a/discord/commands/context.py b/discord/commands/context.py index dbc40d1043..11150b3d1b 100644 --- a/discord/commands/context.py +++ b/discord/commands/context.py @@ -256,13 +256,29 @@ def defer(self) -> Callable[..., Awaitable[None]]: def followup(self) -> Webhook: return self.interaction.followup - async def delete(self): - """Calls :attr:`~discord.commands.ApplicationContext.respond`. - If the response is done, then calls :attr:`~discord.commands.ApplicationContext.respond` first.""" + async def delete(self, *, delay: Optional[float] = None) -> None: + """|coro| + + Deletes the original interaction response message. + + This is a higher level interface to :meth:`Interaction.delete_original_message`. + + Parameters + ----------- + delay: Optional[:class:`float`] + If provided, the number of seconds to wait before deleting the message. + + Raises + ------- + HTTPException + Deleting the message failed. + Forbidden + You do not have proper permissions to delete the message. + """ if not self.interaction.response.is_done(): await self.defer() - return await self.interaction.delete_original_message() + return await self.interaction.delete_original_message(delay=delay) @property def edit(self) -> Callable[..., Awaitable[InteractionMessage]]: diff --git a/discord/ext/bridge/context.py b/discord/ext/bridge/context.py index f65f2309f4..9d17316ec2 100644 --- a/discord/ext/bridge/context.py +++ b/discord/ext/bridge/context.py @@ -145,7 +145,7 @@ def __init__(self, *args, **kwargs): async def _respond(self, *args, **kwargs) -> Message: message = await self._get_super("reply")(*args, **kwargs) - if self._original_response_message == None: + if self._original_response_message is None: self._original_response_message = message return message @@ -155,6 +155,21 @@ async def _defer(self, *args, **kwargs) -> None: async def _edit(self, *args, **kwargs) -> Message: return await self._original_response_message.edit(*args, **kwargs) + async def delete(self, *, delay: Optional[float] = None, reason: Optional[str] = None) -> None: + """|coro| + + Deletes the original response message, if it exists. + + Parameters + ----------- + delay: Optional[:class:`float`] + If provided, the number of seconds to wait before deleting the message. + reason: Optional[:class:`str`] + The reason for deleting the message. Shows up on the audit log. + """ + if self._original_response_message: + await self._original_response_message.delete(delay=delay, reason=reason) + if TYPE_CHECKING: # This is a workaround for mypy not being able to resolve the type of BridgeCommand.