diff options
| author | Rapptz <[email protected]> | 2016-12-25 17:50:40 -0500 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2017-01-03 09:52:04 -0500 |
| commit | 4e175d36d3453c5c08ae398442f22151725f7e0e (patch) | |
| tree | a33f86dbc2eebf986c174fe23bb3215ac1ceffd6 /discord/abc.py | |
| parent | [commands] Remove send_ utility functions. (diff) | |
| download | discord.py-4e175d36d3453c5c08ae398442f22151725f7e0e.tar.xz discord.py-4e175d36d3453c5c08ae398442f22151725f7e0e.zip | |
Add delete_after parameter to MessageChannel.send
Diffstat (limited to 'discord/abc.py')
| -rw-r--r-- | discord/abc.py | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/discord/abc.py b/discord/abc.py index e609faf2..81bb4105 100644 --- a/discord/abc.py +++ b/discord/abc.py @@ -145,7 +145,7 @@ class MessageChannel(metaclass=abc.ABCMeta): raise NotImplementedError @asyncio.coroutine - def send(self, content=None, *, tts=False, embed=None, file=None, filename=None): + def send(self, content=None, *, tts=False, embed=None, file=None, filename=None, delete_after=None): """|coro| Sends a message to the channel with the content given. @@ -185,6 +185,10 @@ class MessageChannel(metaclass=abc.ABCMeta): The filename of the file. Defaults to ``file.name`` if it's available. If this is provided, you must also provide the ``file`` parameter or it is silently ignored. + delete_after: float + If provided, the number of seconds to wait in the background + before deleting the message we just sent. If the deletion fails, + then it is silently ignored. Raises -------- @@ -219,7 +223,17 @@ class MessageChannel(metaclass=abc.ABCMeta): else: data = yield from state.http.send_message(channel_id, content, guild_id=guild_id, tts=tts, embed=embed) - return Message(channel=self, state=state, data=data) + ret = Message(channel=self, state=state, data=data) + if delete_after is not None: + @asyncio.coroutine + def delete(): + yield from asyncio.sleep(delete_after, loop=state.loop) + try: + yield from ret.delete() + except: + pass + discord.compat.create_task(delete(), loop=state.loop) + return ret @asyncio.coroutine def send_typing(self): |