81
81
from .poll import Poll
82
82
from .state import ConnectionState
83
83
from .threads import Thread
84
- from .types .interactions import Interaction as InteractionPayload
84
+ from .types .interactions import Interaction as InteractionPayload , InteractionCallbackResponse
85
85
from .types .interactions import InteractionData
86
86
from .types .interactions import InteractionMetadata as InteractionMetadataPayload
87
87
from .types .interactions import MessageInteraction as MessageInteractionPayload
@@ -129,6 +129,7 @@ class Interaction:
129
129
The user or member that sent the interaction. Will be `None` in PING interactions.
130
130
message: Optional[:class:`Message`]
131
131
The message that sent this interaction.
132
+ This is updated to the message object of the response after responding by sending or editing a message.
132
133
token: :class:`str`
133
134
The token to continue the interaction. These are valid
134
135
for 15 minutes.
@@ -185,12 +186,16 @@ class Interaction:
185
186
"_cs_response" ,
186
187
"_cs_followup" ,
187
188
"_cs_channel" ,
189
+ "_response_message_loading" ,
190
+ "_response_message_ephemeral" ,
188
191
)
189
192
190
193
def __init__ (self , * , data : InteractionPayload , state : ConnectionState ):
191
194
self ._state : ConnectionState = state
192
195
self ._session : ClientSession = state .http ._HTTPClient__session
193
196
self ._original_response : InteractionMessage | None = None
197
+ self ._response_message_loading : bool = False
198
+ self ._response_message_ephemeral : bool = False
194
199
self ._from_data (data )
195
200
196
201
def _from_data (self , data : InteractionPayload ):
@@ -308,6 +313,22 @@ def is_component(self) -> bool:
308
313
"""Indicates whether the interaction is a message component."""
309
314
return self .type == InteractionType .component
310
315
316
+ def is_loading (self ) -> bool :
317
+ """Indicates whether the response message is in a loading state.
318
+
319
+ .. versionadded:: 2.7
320
+ """
321
+ return self ._response_message_loading
322
+
323
+ def is_ephemeral (self ) -> bool :
324
+ """Indicates whether the response message is ephemeral.
325
+
326
+ This might be useful for determining if the message was forced to be ephemeral.
327
+
328
+ .. versionadded:: 2.7
329
+ """
330
+ return self ._response_message_ephemeral
331
+
311
332
@utils .cached_slot_property ("_cs_channel" )
312
333
@utils .deprecated ("Interaction.channel" , "2.7" , stacklevel = 4 )
313
334
def cached_channel (self ) -> InteractionChannel | None :
@@ -871,6 +892,19 @@ async def pong(self) -> None:
871
892
)
872
893
self ._responded = True
873
894
895
+ async def _process_callback_response (self , callback_response : InteractionCallbackResponse ):
896
+ if callback_response .get ("resource" ) and callback_response ["resource" ].get ("message" ):
897
+ # TODO: fix later to not raise?
898
+ channel = self ._parent .channel
899
+ if channel is None :
900
+ raise ClientException ("Channel for message could not be resolved" )
901
+ state = _InteractionMessageState (self ._parent , self ._parent ._state )
902
+ message = InteractionMessage (state = state , channel = channel , data = callback_response ["resource" ]["message" ]) # type: ignore
903
+ self ._parent ._original_response = message
904
+
905
+ self ._parent ._response_message_ephemeral = callback_response ["interaction" ].get ("response_message_ephemeral" , False )
906
+ self ._parent ._response_message_loading = callback_response ["interaction" ].get ("response_message_loading" , False )
907
+
874
908
async def send_message (
875
909
self ,
876
910
content : Any | None = None ,
@@ -1007,7 +1041,7 @@ async def send_message(
1007
1041
adapter = async_context .get ()
1008
1042
http = parent ._state .http
1009
1043
try :
1010
- await self ._locked_response (
1044
+ callback_response : InteractionCallbackResponse = await self ._locked_response (
1011
1045
adapter .create_interaction_response (
1012
1046
parent .id ,
1013
1047
parent .token ,
@@ -1031,6 +1065,8 @@ async def send_message(
1031
1065
view .parent = self ._parent
1032
1066
self ._parent ._state .store_view (view )
1033
1067
1068
+ await self ._process_callback_response (callback_response )
1069
+
1034
1070
self ._responded = True
1035
1071
if delete_after is not None :
1036
1072
await self ._parent .delete_original_response (delay = delete_after )
@@ -1171,7 +1207,7 @@ async def edit_message(
1171
1207
adapter = async_context .get ()
1172
1208
http = parent ._state .http
1173
1209
try :
1174
- await self ._locked_response (
1210
+ callback_response : InteractionCallbackResponse = await self ._locked_response (
1175
1211
adapter .create_interaction_response (
1176
1212
parent .id ,
1177
1213
parent .token ,
@@ -1192,6 +1228,8 @@ async def edit_message(
1192
1228
view .message = msg
1193
1229
state .store_view (view , message_id )
1194
1230
1231
+ await self ._process_callback_response (callback_response )
1232
+
1195
1233
self ._responded = True
1196
1234
if delete_after is not None :
1197
1235
await self ._parent .delete_original_response (delay = delete_after )
@@ -1319,7 +1357,7 @@ async def premium_required(self) -> Interaction:
1319
1357
self ._responded = True
1320
1358
return self ._parent
1321
1359
1322
- async def _locked_response (self , coro : Coroutine [Any , Any , Any ]) -> None :
1360
+ async def _locked_response (self , coro : Coroutine [Any , Any , Any ]) -> Any :
1323
1361
"""|coro|
1324
1362
1325
1363
Wraps a response and makes sure that it's locked while executing.
@@ -1338,7 +1376,7 @@ async def _locked_response(self, coro: Coroutine[Any, Any, Any]) -> None:
1338
1376
if self .is_done ():
1339
1377
coro .close () # cleanup un-awaited coroutine
1340
1378
raise InteractionResponded (self ._parent )
1341
- await coro
1379
+ return await coro
1342
1380
1343
1381
1344
1382
class _InteractionMessageState :
0 commit comments