@@ -154,9 +154,14 @@ class Attachment(Hashable):
154
154
Whether the attachment is ephemeral or not.
155
155
156
156
.. versionadded:: 1.7
157
+
158
+ description: Optional[:class:`str`]
159
+ The attachment's description.
160
+
161
+ .. versionadded:: 2.0
157
162
"""
158
163
159
- __slots__ = ('id' , 'size' , 'height' , 'width' , 'filename' , 'url' , 'proxy_url' , '_http' , 'content_type' , 'ephemeral' )
164
+ __slots__ = ('id' , 'size' , 'height' , 'width' , 'filename' , 'url' , 'proxy_url' , '_http' , 'content_type' , 'ephemeral' , 'description' )
160
165
161
166
def __init__ (self , * , data : AttachmentPayload , state : ConnectionState ):
162
167
self .id : int = int (data ['id' ])
@@ -169,6 +174,7 @@ def __init__(self, *, data: AttachmentPayload, state: ConnectionState):
169
174
self ._http = state .http
170
175
self .content_type : Optional [str ] = data .get ('content_type' )
171
176
self .ephemeral : bool = data .get ('ephemeral' , False )
177
+ self .description : Optional [str ] = data .get ('description' )
172
178
173
179
def is_spoiler (self ) -> bool :
174
180
""":class:`bool`: Whether this attachment contains a spoiler."""
@@ -305,7 +311,7 @@ async def to_file(self, *, use_cached: bool = False, spoiler: bool = False) -> F
305
311
"""
306
312
307
313
data = await self .read (use_cached = use_cached )
308
- return File (io .BytesIO (data ), filename = self .filename , spoiler = spoiler )
314
+ return File (io .BytesIO (data ), filename = self .filename , spoiler = spoiler , description = self . description )
309
315
310
316
def to_dict (self ) -> AttachmentPayload :
311
317
result : AttachmentPayload = {
@@ -322,6 +328,8 @@ def to_dict(self) -> AttachmentPayload:
322
328
result ['width' ] = self .width
323
329
if self .content_type :
324
330
result ['content_type' ] = self .content_type
331
+ if self .description :
332
+ result ['description' ] = self .description
325
333
return result
326
334
327
335
@@ -1312,6 +1320,9 @@ async def edit(
1312
1320
raise InvalidArgument ('cannot pass both file and files parameter to edit()' )
1313
1321
1314
1322
if file is not MISSING :
1323
+ if 'attachments' not in payload :
1324
+ # don't want it to remove any attachments when we just add a new file
1325
+ payload ['attachments' ] = [a .to_dict () for a in self .attachments ]
1315
1326
if not isinstance (file , File ):
1316
1327
raise InvalidArgument ('file parameter must be File' )
1317
1328
@@ -1330,6 +1341,9 @@ async def edit(
1330
1341
raise InvalidArgument ('files parameter must be a list of up to 10 elements' )
1331
1342
elif not all (isinstance (file , File ) for file in files ):
1332
1343
raise InvalidArgument ('files parameter must be a list of File' )
1344
+ if 'attachments' not in payload :
1345
+ # don't want it to remove any attachments when we just add a new file
1346
+ payload ['attachments' ] = [a .to_dict () for a in self .attachments ]
1333
1347
1334
1348
try :
1335
1349
data = await self ._state .http .edit_files (
0 commit comments