@@ -677,6 +677,8 @@ async def edit_message(
677
677
content : Optional [Any ] = MISSING ,
678
678
embed : Optional [Embed ] = MISSING ,
679
679
embeds : List [Embed ] = MISSING ,
680
+ file : File = MISSING ,
681
+ files : List [File ] = MISSING ,
680
682
attachments : List [Attachment ] = MISSING ,
681
683
view : Optional [View ] = MISSING ,
682
684
delete_after : Optional [float ] = None ,
@@ -695,6 +697,11 @@ async def edit_message(
695
697
embed: Optional[:class:`Embed`]
696
698
The embed to edit the message with. ``None`` suppresses the embeds.
697
699
This should not be mixed with the ``embeds`` parameter.
700
+ file: :class:`File`
701
+ A new file to add to the message. This cannot be mixed with ``files`` parameter.
702
+ files: List[:class:`File`]
703
+ A list of new files to add to the message. Must be a maximum of 10. This
704
+ cannot be mixed with the ``file`` parameter.
698
705
attachments: List[:class:`Attachment`]
699
706
A list of attachments to keep in the message. If ``[]`` is passed
700
707
then all attachments are removed.
@@ -742,16 +749,44 @@ async def edit_message(
742
749
if view is not MISSING :
743
750
state .prevent_view_updates_for (message_id )
744
751
payload ["components" ] = [] if view is None else view .to_components ()
752
+
753
+ if file is not MISSING and files is not MISSING :
754
+ raise InvalidArgument ("cannot pass both file and files parameter to edit_message()" )
755
+
756
+ if file is not MISSING :
757
+ if not isinstance (file , File ):
758
+ raise InvalidArgument ("file parameter must be a File" )
759
+ else :
760
+ files = [file ]
761
+ if "attachments" not in payload :
762
+ # we keep previous attachments when adding a new file
763
+ payload ["attachments" ] = [a .to_dict () for a in msg .attachments ]
764
+
765
+ if files is not MISSING :
766
+ if len (files ) > 10 :
767
+ raise InvalidArgument ("files parameter must be a list of up to 10 elements" )
768
+ elif not all (isinstance (file , File ) for file in files ):
769
+ raise InvalidArgument ("files parameter must be a list of File" )
770
+ if "attachments" not in payload :
771
+ # we keep previous attachments when adding new files
772
+ payload ["attachments" ] = [a .to_dict () for a in msg .attachments ]
773
+
745
774
adapter = async_context .get ()
746
- await self ._locked_response (
747
- adapter .create_interaction_response (
748
- parent .id ,
749
- parent .token ,
750
- session = parent ._session ,
751
- type = InteractionResponseType .message_update .value ,
752
- data = payload ,
775
+ try :
776
+ await self ._locked_response (
777
+ adapter .create_interaction_response (
778
+ parent .id ,
779
+ parent .token ,
780
+ session = parent ._session ,
781
+ type = InteractionResponseType .message_update .value ,
782
+ data = payload ,
783
+ files = files ,
784
+ )
753
785
)
754
- )
786
+ finally :
787
+ if files :
788
+ for file in files :
789
+ file .close ()
755
790
756
791
if view and not view .is_finished ():
757
792
state .store_view (view , message_id )
0 commit comments