diff options
| author | Maku <[email protected]> | 2020-02-23 22:12:16 -0500 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2020-04-04 03:03:20 -0400 |
| commit | c2d5c2e1187c38445ad384fb743f4cf5f78d82f1 (patch) | |
| tree | c290c10dfd297a5252071f8555ec5dc1a4a7fa3f | |
| parent | [tasks] Add is_running property to Loop (diff) | |
| download | discord.py-c2d5c2e1187c38445ad384fb743f4cf5f78d82f1.tar.xz discord.py-c2d5c2e1187c38445ad384fb743f4cf5f78d82f1.zip | |
Add use_cached to Attachment.to_file
| -rw-r--r-- | discord/message.py | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/discord/message.py b/discord/message.py index e1b88f12..abad3bb1 100644 --- a/discord/message.py +++ b/discord/message.py @@ -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): |