Skip to content

Commit 8b42c46

Browse files
amachnDorukyum
andauthored
Add BridgeExtContext.delete() method (#1348)
* Update delete methods * Consolidate into ext.bridge.context * Update discord/commands/context.py Co-authored-by: Dorukyum <[email protected]>
1 parent 702daef commit 8b42c46

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

discord/commands/context.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,29 @@ def defer(self) -> Callable[..., Awaitable[None]]:
256256
def followup(self) -> Webhook:
257257
return self.interaction.followup
258258

259-
async def delete(self):
260-
"""Calls :attr:`~discord.commands.ApplicationContext.respond`.
261-
If the response is done, then calls :attr:`~discord.commands.ApplicationContext.respond` first."""
259+
async def delete(self, *, delay: Optional[float] = None) -> None:
260+
"""|coro|
261+
262+
Deletes the original interaction response message.
263+
264+
This is a higher level interface to :meth:`Interaction.delete_original_message`.
265+
266+
Parameters
267+
-----------
268+
delay: Optional[:class:`float`]
269+
If provided, the number of seconds to wait before deleting the message.
270+
271+
Raises
272+
-------
273+
HTTPException
274+
Deleting the message failed.
275+
Forbidden
276+
You do not have proper permissions to delete the message.
277+
"""
262278
if not self.interaction.response.is_done():
263279
await self.defer()
264280

265-
return await self.interaction.delete_original_message()
281+
return await self.interaction.delete_original_message(delay=delay)
266282

267283
@property
268284
def edit(self) -> Callable[..., Awaitable[InteractionMessage]]:

discord/ext/bridge/context.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def __init__(self, *args, **kwargs):
145145

146146
async def _respond(self, *args, **kwargs) -> Message:
147147
message = await self._get_super("reply")(*args, **kwargs)
148-
if self._original_response_message == None:
148+
if self._original_response_message is None:
149149
self._original_response_message = message
150150
return message
151151

@@ -155,6 +155,21 @@ async def _defer(self, *args, **kwargs) -> None:
155155
async def _edit(self, *args, **kwargs) -> Message:
156156
return await self._original_response_message.edit(*args, **kwargs)
157157

158+
async def delete(self, *, delay: Optional[float] = None, reason: Optional[str] = None) -> None:
159+
"""|coro|
160+
161+
Deletes the original response message, if it exists.
162+
163+
Parameters
164+
-----------
165+
delay: Optional[:class:`float`]
166+
If provided, the number of seconds to wait before deleting the message.
167+
reason: Optional[:class:`str`]
168+
The reason for deleting the message. Shows up on the audit log.
169+
"""
170+
if self._original_response_message:
171+
await self._original_response_message.delete(delay=delay, reason=reason)
172+
158173

159174
if TYPE_CHECKING:
160175
# This is a workaround for mypy not being able to resolve the type of BridgeCommand.

0 commit comments

Comments
 (0)