aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaku <[email protected]>2019-03-06 17:01:18 -0500
committerRapptz <[email protected]>2019-03-06 20:04:40 -0500
commit6f1dff78d4daeba49603f81c473fa7098c5483d2 (patch)
tree39c76d2632473ed5d1d2bcdd81a42e31a28495b1
parentFix non-working example in commands documentation. (diff)
downloaddiscord.py-6f1dff78d4daeba49603f81c473fa7098c5483d2.tar.xz
discord.py-6f1dff78d4daeba49603f81c473fa7098c5483d2.zip
Added cached saving for attachments
Updated docstring
-rw-r--r--discord/message.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/discord/message.py b/discord/message.py
index ca7b9ee3..ef4fae54 100644
--- a/discord/message.py
+++ b/discord/message.py
@@ -77,7 +77,7 @@ class Attachment:
""":class:`bool`: Whether this attachment contains a spoiler."""
return self.filename.startswith('SPOILER_')
- async def save(self, fp, *, seek_begin=True):
+ async def save(self, fp, *, seek_begin=True, use_cached=False):
"""|coro|
Saves this attachment into a file-like object.
@@ -91,6 +91,12 @@ class Attachment:
seek_begin: bool
Whether to seek to the beginning of the file after saving is
successfully done.
+ use_cached: bool
+ Whether to use the proxy_url property, rather than the url
+ property, as the attachment source. This will allow attachments
+ to be saved after deletion more often than with the url, which
+ is deleted after the message is deleted. Note that use_cached will
+ still fail after an uncertain amount of time.
Raises
--------
@@ -104,8 +110,8 @@ class Attachment:
int
The number of bytes written.
"""
-
- data = await self._http.get_attachment(self.url)
+ url = self.proxy_url if use_cached else self.url
+ data = await self._http.get_attachment(url)
if isinstance(fp, str):
with open(fp, 'wb') as f:
return f.write(data)