@@ -1183,6 +1183,8 @@ async def edit(
1183
1183
content : Optional [str ] = MISSING ,
1184
1184
embed : Optional [Embed ] = MISSING ,
1185
1185
embeds : List [Embed ] = MISSING ,
1186
+ file : Sequence [File ] = MISSING ,
1187
+ files : List [Sequence [File ]] = MISSING ,
1186
1188
attachments : List [Attachment ] = MISSING ,
1187
1189
suppress : bool = MISSING ,
1188
1190
delete_after : Optional [float ] = None ,
@@ -1211,6 +1213,10 @@ async def edit(
1211
1213
To remove all embeds ``[]`` should be passed.
1212
1214
1213
1215
.. versionadded:: 2.0
1216
+ file: Sequence[:class:`File`]
1217
+ A new file to add to the message.
1218
+ files: List[Sequence[:class:`File`]]
1219
+ New files to add to the message.
1214
1220
attachments: List[:class:`Attachment`]
1215
1221
A list of attachments to keep in the message. If ``[]`` is passed
1216
1222
then all attachments are removed.
@@ -1244,7 +1250,8 @@ async def edit(
1244
1250
Tried to suppress a message without permissions or
1245
1251
edited a message's content or embed that isn't yours.
1246
1252
~discord.InvalidArgument
1247
- You specified both ``embed`` and ``embeds``
1253
+ You specified both ``embed`` and ``embeds`` or
1254
+ specified both ``file`` and ``files``.
1248
1255
"""
1249
1256
1250
1257
payload : Dict [str , Any ] = {}
@@ -1289,8 +1296,54 @@ async def edit(
1289
1296
payload ['components' ] = view .to_components ()
1290
1297
else :
1291
1298
payload ['components' ] = []
1299
+
1300
+ if file is not None and files is not None :
1301
+ raise InvalidArgument ('cannot pass both file and files parameter to send()' )
1292
1302
1293
- data = await self ._state .http .edit_message (self .channel .id , self .id , ** payload )
1303
+ if file is not None :
1304
+ if not isinstance (file , File ):
1305
+ raise InvalidArgument ('file parameter must be File' )
1306
+
1307
+ try :
1308
+ data = await state .http .edit_files (
1309
+ channel .id ,
1310
+ self .id ,
1311
+ files = [file ],
1312
+ attachments = attachments ,
1313
+ suppress = suppress ,
1314
+ allowed_mentions = allowed_mentions ,
1315
+ content = content ,
1316
+ embed = embed ,
1317
+ embeds = embeds ,
1318
+ components = components ,
1319
+ )
1320
+ finally :
1321
+ file .close ()
1322
+
1323
+ elif files is not None :
1324
+ if len (files ) > 10 :
1325
+ raise InvalidArgument ('files parameter must be a list of up to 10 elements' )
1326
+ elif not all (isinstance (file , File ) for file in files ):
1327
+ raise InvalidArgument ('files parameter must be a list of File' )
1328
+
1329
+ try :
1330
+ data = await state .http .edit_files (
1331
+ channel .id ,
1332
+ self .id ,
1333
+ files = files ,
1334
+ attachments = attachments ,
1335
+ suppress = suppress ,
1336
+ content = content ,
1337
+ embed = embed ,
1338
+ embeds = embeds ,
1339
+ allowed_mentions = allowed_mentions ,
1340
+ components = components ,
1341
+ )
1342
+ finally :
1343
+ for f in files :
1344
+ f .close ()
1345
+ else :
1346
+ data = await self ._state .http .edit_message (self .channel .id , self .id , ** payload )
1294
1347
message = Message (state = self ._state , channel = self .channel , data = data )
1295
1348
1296
1349
if view and not view .is_finished ():
0 commit comments