mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-10-21 16:03:10 +00:00
Add filename and description kwargs for to_file
This commit is contained in:
@@ -303,7 +303,14 @@ class Attachment(Hashable):
|
||||
data = await self._http.get_from_cdn(url)
|
||||
return data
|
||||
|
||||
async def to_file(self, *, use_cached: bool = False, spoiler: bool = False) -> File:
|
||||
async def to_file(
|
||||
self,
|
||||
*,
|
||||
filename: Optional[str] = MISSING,
|
||||
description: Optional[str] = MISSING,
|
||||
use_cached: bool = False,
|
||||
spoiler: bool = False,
|
||||
) -> File:
|
||||
"""|coro|
|
||||
|
||||
Converts the attachment into a :class:`File` suitable for sending via
|
||||
@@ -313,6 +320,16 @@ class Attachment(Hashable):
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
filename: Optional[:class:`str`]
|
||||
The filename to use for the file. If not specified then the filename
|
||||
of the attachment is used instead.
|
||||
|
||||
.. versionadded:: 2.0
|
||||
description: Optional[:class:`str`]
|
||||
The description to use for the file. If not specified then the
|
||||
description of the attachment is used instead.
|
||||
|
||||
.. versionadded:: 2.0
|
||||
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
|
||||
@@ -343,7 +360,9 @@ class Attachment(Hashable):
|
||||
"""
|
||||
|
||||
data = await self.read(use_cached=use_cached)
|
||||
return File(io.BytesIO(data), filename=self.filename, description=self.description, spoiler=spoiler)
|
||||
file_filename = filename if filename is not MISSING else self.filename
|
||||
file_description = description if description is not MISSING else self.description
|
||||
return File(io.BytesIO(data), filename=file_filename, description=file_description, spoiler=spoiler)
|
||||
|
||||
def to_dict(self) -> AttachmentPayload:
|
||||
result: AttachmentPayload = {
|
||||
|
Reference in New Issue
Block a user