Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add delay kwarg to message.delete() #2094

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 1 addition & 7 deletions discord/abc.py
Expand Up @@ -784,13 +784,7 @@ async def send(self, content=None, *, tts=False, embed=None, file=None, files=No

ret = state.create_message(channel=channel, data=data)
if delete_after is not None:
async def delete():
await asyncio.sleep(delete_after, loop=state.loop)
try:
await ret.delete()
except HTTPException:
pass
asyncio.ensure_future(delete(), loop=state.loop)
await ret.delete(delay=delete_after)
return ret

async def trigger_typing(self):
Expand Down
29 changes: 19 additions & 10 deletions discord/message.py
Expand Up @@ -563,7 +563,7 @@ def system_content(self):
else:
return '{0.author.name} started a call \N{EM DASH} Join the call.'.format(self)

async def delete(self):
async def delete(self, *, delay=None):
"""|coro|

Deletes the message.
Expand All @@ -572,14 +572,30 @@ async def delete(self):
delete other people's messages, you need the :attr:`~Permissions.manage_messages`
permission.

Parameters
-----------
delay: Optional[:class:`float`]
If provided, the number of seconds to wait in the background
before deleting the message.

Raises
------
Forbidden
You do not have proper permissions to delete the message.
HTTPException
Deleting the message failed.
"""
await self._state.http.delete_message(self.channel.id, self.id)
if delay is not None:
async def delete():
await asyncio.sleep(delay, loop=self._state.loop)
try:
await self._state.http.delete_message(self.channel.id, self.id)
except HTTPException:
pass

asyncio.ensure_future(delete(), loop=self._state.loop)
else:
await self._state.http.delete_message(self.channel.id, self.id)

async def edit(self, **fields):
"""|coro|
Expand Down Expand Up @@ -632,14 +648,7 @@ async def edit(self, **fields):
pass
else:
if delete_after is not None:
async def delete():
await asyncio.sleep(delete_after, loop=self._state.loop)
try:
await self._state.http.delete_message(self.channel.id, self.id)
except HTTPException:
pass

asyncio.ensure_future(delete(), loop=self._state.loop)
await self.delete(delay=delete_after)

async def pin(self):
"""|coro|
Expand Down