Add delete_after to 'edit'.
Allow for edited messages to be deleted after [float] seconds with optional parameter delete_after.
This commit is contained in:
parent
d8360411ea
commit
adf99eb2cd
@ -27,7 +27,7 @@ DEALINGS IN THE SOFTWARE.
|
|||||||
import asyncio
|
import asyncio
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from . import utils
|
from . import utils, compat
|
||||||
from .reaction import Reaction
|
from .reaction import Reaction
|
||||||
from .emoji import Emoji, PartialReactionEmoji
|
from .emoji import Emoji, PartialReactionEmoji
|
||||||
from .calls import CallMessage
|
from .calls import CallMessage
|
||||||
@ -514,6 +514,10 @@ 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.
|
||||||
|
delete_after: Optional[float]
|
||||||
|
If provided, the number of seconds to wait in the background
|
||||||
|
before deleting the message we just edited. If the deletion fails,
|
||||||
|
then it is silently ignored.
|
||||||
|
|
||||||
Raises
|
Raises
|
||||||
-------
|
-------
|
||||||
@ -540,6 +544,22 @@ class Message:
|
|||||||
data = yield from self._state.http.edit_message(self.id, self.channel.id, **fields)
|
data = yield from self._state.http.edit_message(self.id, self.channel.id, **fields)
|
||||||
self._update(channel=self.channel, data=data)
|
self._update(channel=self.channel, data=data)
|
||||||
|
|
||||||
|
try:
|
||||||
|
delete_after = fields['delete_after']
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
if delete_after is not None:
|
||||||
|
@asyncio.coroutine
|
||||||
|
def delete():
|
||||||
|
yield from asyncio.sleep(delete_after, loop=self._state.loop)
|
||||||
|
try:
|
||||||
|
yield from self._state.http.delete_message(self.channel.id, self.id)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
compat.create_task(delete(), loop=self._state.loop)
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def pin(self):
|
def pin(self):
|
||||||
"""|coro|
|
"""|coro|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user