Skip to content

Commit

Permalink
Reduces redundancy for 1 or more files (Pycord-Development#1400)
Browse files Browse the repository at this point in the history
* Reduces redundancy for 1 or more files

* Added back check to check if file is type file
  • Loading branch information
UP929312 authored Jun 22, 2022
1 parent ca21103 commit c9870e1
Showing 1 changed file with 11 additions and 23 deletions.
34 changes: 11 additions & 23 deletions discord/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -1320,32 +1320,20 @@ async def edit(
if file is not MISSING and files is not MISSING:
raise InvalidArgument("cannot pass both file and files parameter to edit()")

if file is not MISSING:
if "attachments" not in payload:
# don't want it to remove any attachments when we just add a new file
payload["attachments"] = [a.to_dict() for a in self.attachments]
if not isinstance(file, File):
raise InvalidArgument("file parameter must be File")

try:
data = await self._state.http.edit_files(
self.channel.id,
self.id,
files=[file],
**payload,
)
finally:
file.close()

elif files is not MISSING:
if len(files) > 10:
raise InvalidArgument("files parameter must be a list of up to 10 elements")
elif not all(isinstance(file, File) for file in files):
raise InvalidArgument("files parameter must be a list of File")
if file is not MISSING or files is not MISSING:
if file is not MISSING:
if not isinstance(file, File):
raise InvalidArgument("file parameter must be of type File")
files = [file]
else:
if len(files) > 10:
raise InvalidArgument("files parameter must be a list of up to 10 elements")
elif not all(isinstance(file, File) for file in files):
raise InvalidArgument("files parameter must be a list of File")

if "attachments" not in payload:
# don't want it to remove any attachments when we just add a new file
payload["attachments"] = [a.to_dict() for a in self.attachments]

try:
data = await self._state.http.edit_files(
self.channel.id,
Expand Down

0 comments on commit c9870e1

Please sign in to comment.