Add use_cached to Attachment.to_file

This commit is contained in:
Maku 2020-02-23 22:12:16 -05:00 committed by Rapptz
parent 6a30f2749f
commit c2d5c2e118

View File

@ -166,7 +166,7 @@ class Attachment:
data = await self._http.get_from_cdn(url)
return data
async def to_file(self):
async def to_file(self, use_cached=False):
"""|coro|
Converts the attachment into a :class:`File` suitable for sending via
@ -174,6 +174,16 @@ class Attachment:
.. versionadded:: 1.3
Parameters
-----------
use_cached: :class:`bool`
Whether to use :attr:`proxy_url` rather than :attr:`url` when downloading
the attachment. This will allow attachments to be saved after deletion
more often, compared to the regular URL which is generally deleted right
after the message is deleted. Note that this can still fail to download
deleted attachments if too much time has passed and it does not work
on some types of attachments.
Raises
------
HTTPException
@ -189,7 +199,7 @@ class Attachment:
The attachment as a file suitable for sending.
"""
data = await self.read()
data = await self.read(use_cached=use_cached)
return File(io.BytesIO(data), filename=self.filename)
def flatten_handlers(cls):