Skip to content

Commit 3557874

Browse files
authored
Added file and files keyword arguments
Added file and files keyword arguments into the edit function Edited docstrings for the file and files keyword arguments
1 parent d78a85d commit 3557874

File tree

1 file changed

+55
-2
lines changed

1 file changed

+55
-2
lines changed

discord/message.py

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,6 +1183,8 @@ async def edit(
11831183
content: Optional[str] = MISSING,
11841184
embed: Optional[Embed] = MISSING,
11851185
embeds: List[Embed] = MISSING,
1186+
file: Sequence[File] = MISSING,
1187+
files: List[Sequence[File]] = MISSING,
11861188
attachments: List[Attachment] = MISSING,
11871189
suppress: bool = MISSING,
11881190
delete_after: Optional[float] = None,
@@ -1211,6 +1213,10 @@ async def edit(
12111213
To remove all embeds ``[]`` should be passed.
12121214
12131215
.. 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.
12141220
attachments: List[:class:`Attachment`]
12151221
A list of attachments to keep in the message. If ``[]`` is passed
12161222
then all attachments are removed.
@@ -1244,7 +1250,8 @@ async def edit(
12441250
Tried to suppress a message without permissions or
12451251
edited a message's content or embed that isn't yours.
12461252
~discord.InvalidArgument
1247-
You specified both ``embed`` and ``embeds``
1253+
You specified both ``embed`` and ``embeds`` or
1254+
specified both ``file`` and ``files``.
12481255
"""
12491256

12501257
payload: Dict[str, Any] = {}
@@ -1289,8 +1296,54 @@ async def edit(
12891296
payload['components'] = view.to_components()
12901297
else:
12911298
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()')
12921302

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)
12941347
message = Message(state=self._state, channel=self.channel, data=data)
12951348

12961349
if view and not view.is_finished():

0 commit comments

Comments
 (0)