@@ -1156,6 +1156,22 @@ async def edit(
1156
1156
* ,
1157
1157
content : Optional [str ] = ...,
1158
1158
embed : Optional [Embed ] = ...,
1159
+ file : Optional [File ] = ...,
1160
+ attachments : List [Attachment ] = ...,
1161
+ suppress : bool = ...,
1162
+ delete_after : Optional [float ] = ...,
1163
+ allowed_mentions : Optional [AllowedMentions ] = ...,
1164
+ view : Optional [View ] = ...,
1165
+ ) -> Message :
1166
+ ...
1167
+
1168
+ @overload
1169
+ async def edit (
1170
+ self ,
1171
+ * ,
1172
+ content : Optional [str ] = ...,
1173
+ embed : Optional [Embed ] = ...,
1174
+ files : Optional [List [File ]] = ...,
1159
1175
attachments : List [Attachment ] = ...,
1160
1176
suppress : bool = ...,
1161
1177
delete_after : Optional [float ] = ...,
@@ -1170,6 +1186,7 @@ async def edit(
1170
1186
* ,
1171
1187
content : Optional [str ] = ...,
1172
1188
embeds : List [Embed ] = ...,
1189
+ file : File = ...,
1173
1190
attachments : List [Attachment ] = ...,
1174
1191
suppress : bool = ...,
1175
1192
delete_after : Optional [float ] = ...,
@@ -1183,6 +1200,8 @@ async def edit(
1183
1200
content : Optional [str ] = MISSING ,
1184
1201
embed : Optional [Embed ] = MISSING ,
1185
1202
embeds : List [Embed ] = MISSING ,
1203
+ file : Sequence [File ] = MISSING ,
1204
+ files : List [Sequence [File ]] = MISSING ,
1186
1205
attachments : List [Attachment ] = MISSING ,
1187
1206
suppress : bool = MISSING ,
1188
1207
delete_after : Optional [float ] = None ,
@@ -1211,6 +1230,10 @@ async def edit(
1211
1230
To remove all embeds ``[]`` should be passed.
1212
1231
1213
1232
.. versionadded:: 2.0
1233
+ file: Sequence[:class:`File`]
1234
+ A new file to add to the message.
1235
+ files: List[Sequence[:class:`File`]]
1236
+ New files to add to the message.
1214
1237
attachments: List[:class:`Attachment`]
1215
1238
A list of attachments to keep in the message. If ``[]`` is passed
1216
1239
then all attachments are removed.
@@ -1244,7 +1267,9 @@ async def edit(
1244
1267
Tried to suppress a message without permissions or
1245
1268
edited a message's content or embed that isn't yours.
1246
1269
~discord.InvalidArgument
1247
- You specified both ``embed`` and ``embeds``
1270
+ You specified both ``embed`` and ``embeds``,
1271
+ specified both ``file`` and ``files``, or either``file``
1272
+ or ``files`` were of the wrong type.
1248
1273
"""
1249
1274
1250
1275
payload : Dict [str , Any ] = {}
@@ -1289,8 +1314,42 @@ async def edit(
1289
1314
payload ['components' ] = view .to_components ()
1290
1315
else :
1291
1316
payload ['components' ] = []
1317
+
1318
+ if file is not MISSING and files is not MISSING :
1319
+ raise InvalidArgument ('cannot pass both file and files parameter to edit()' )
1320
+
1321
+ if file is not MISSING :
1322
+ if not isinstance (file , File ):
1323
+ raise InvalidArgument ('file parameter must be File' )
1292
1324
1293
- data = await self ._state .http .edit_message (self .channel .id , self .id , ** payload )
1325
+ try :
1326
+ data = await self ._state .http .edit_files (
1327
+ self .channel .id ,
1328
+ self .id ,
1329
+ files = [file ],
1330
+ ** payload ,
1331
+ )
1332
+ finally :
1333
+ file .close ()
1334
+
1335
+ elif files is not MISSING :
1336
+ if len (files ) > 10 :
1337
+ raise InvalidArgument ('files parameter must be a list of up to 10 elements' )
1338
+ elif not all (isinstance (file , File ) for file in files ):
1339
+ raise InvalidArgument ('files parameter must be a list of File' )
1340
+
1341
+ try :
1342
+ data = await self ._state .http .edit_files (
1343
+ self .channel .id ,
1344
+ self .id ,
1345
+ files = files ,
1346
+ ** payload ,
1347
+ )
1348
+ finally :
1349
+ for f in files :
1350
+ f .close ()
1351
+ else :
1352
+ data = await self ._state .http .edit_message (self .channel .id , self .id , ** payload )
1294
1353
message = Message (state = self ._state , channel = self .channel , data = data )
1295
1354
1296
1355
if view and not view .is_finished ():
0 commit comments