@@ -788,6 +788,8 @@ class ModalContext(InteractionContext):
788
788
"""The responses of the modal. The key is the `custom_id` of the component."""
789
789
custom_id : str
790
790
"""The developer defined custom ID of this modal"""
791
+ edit_origin : bool
792
+ """Whether to edit the original message instead of sending a new one."""
791
793
792
794
@classmethod
793
795
def from_dict (cls , client : "interactions.Client" , payload : dict ) -> Self :
@@ -797,8 +799,42 @@ def from_dict(cls, client: "interactions.Client", payload: dict) -> Self:
797
799
}
798
800
instance .kwargs = instance .responses
799
801
instance .custom_id = payload ["data" ]["custom_id" ]
802
+ instance .edit_origin = False
800
803
return instance
801
804
805
+ async def edit (self , message : "Snowflake_Type" , ** kwargs ) -> "interactions.Message" :
806
+ if not self .deferred and not self .responded :
807
+ await self .defer (edit_origin = True )
808
+ return await super ().edit (message , ** kwargs )
809
+
810
+ async def defer (self , * , ephemeral : bool = False , edit_origin : bool = False ) -> None :
811
+ """
812
+ Defer the interaction.
813
+
814
+ Args:
815
+ ephemeral: Whether the interaction response should be ephemeral.
816
+ edit_origin: Whether to edit the original message instead of sending a followup.
817
+ """
818
+ if self .deferred :
819
+ raise AlreadyDeferred ("Interaction has already been responded to." )
820
+ if self .responded :
821
+ raise AlreadyResponded ("Interaction has already been responded to." )
822
+
823
+ payload = {
824
+ "type" : CallbackType .DEFERRED_UPDATE_MESSAGE
825
+ if edit_origin
826
+ else CallbackType .DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE
827
+ }
828
+ if ephemeral :
829
+ payload ["data" ] = {"flags" : MessageFlags .EPHEMERAL }
830
+
831
+ if edit_origin :
832
+ self .edit_origin = True
833
+
834
+ await self .client .http .post_initial_response (payload , self .id , self .token )
835
+ self .deferred = True
836
+ self .ephemeral = ephemeral
837
+
802
838
803
839
class AutocompleteContext (BaseInteractionContext ):
804
840
focussed_option : SlashCommandOption # todo: option parsing
0 commit comments