mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-05-15 10:19:59 +00:00
Added cached saving for attachments
Updated docstring
This commit is contained in:
parent
d124daef33
commit
6f1dff78d4
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user