60
60
"MessageInteraction" ,
61
61
"InteractionMetadata" ,
62
62
"AuthorizingIntegrationOwners" ,
63
+ "InteractionCallback"
63
64
)
64
65
65
66
if TYPE_CHECKING :
83
84
from .threads import Thread
84
85
from .types .interactions import Interaction as InteractionPayload
85
86
from .types .interactions import InteractionCallbackResponse , InteractionData
87
+ from .types .interactions import InteractionCallback as InteractionCallbackPayload
86
88
from .types .interactions import InteractionMetadata as InteractionMetadataPayload
87
89
from .types .interactions import MessageInteraction as MessageInteractionPayload
88
90
from .ui .modal import Modal
@@ -152,6 +154,11 @@ class Interaction:
152
154
The context in which this command was executed.
153
155
154
156
.. versionadded:: 2.6
157
+ callback: Optional[:class:`InteractionCallback`]
158
+ The callback of the interaction. Contains information about the status of the interaction response.
159
+ Will be `None` until the interaction is responded to.
160
+
161
+ .. versionadded:: 2.7
155
162
"""
156
163
157
164
__slots__ : tuple [str , ...] = (
@@ -172,6 +179,7 @@ class Interaction:
172
179
"entitlements" ,
173
180
"context" ,
174
181
"authorizing_integration_owners" ,
182
+ "callback" ,
175
183
"_channel_data" ,
176
184
"_message_data" ,
177
185
"_guild_data" ,
@@ -185,16 +193,13 @@ class Interaction:
185
193
"_cs_response" ,
186
194
"_cs_followup" ,
187
195
"_cs_channel" ,
188
- "_response_message_loading" ,
189
- "_response_message_ephemeral" ,
190
196
)
191
197
192
198
def __init__ (self , * , data : InteractionPayload , state : ConnectionState ):
193
199
self ._state : ConnectionState = state
194
200
self ._session : ClientSession = state .http ._HTTPClient__session
195
201
self ._original_response : InteractionMessage | None = None
196
- self ._response_message_loading : bool = False
197
- self ._response_message_ephemeral : bool = False
202
+ self .callback : InteractionCallback | None = None
198
203
self ._from_data (data )
199
204
200
205
def _from_data (self , data : InteractionPayload ):
@@ -312,22 +317,6 @@ def is_component(self) -> bool:
312
317
"""Indicates whether the interaction is a message component."""
313
318
return self .type == InteractionType .component
314
319
315
- def is_loading (self ) -> bool :
316
- """Indicates whether the response message is in a loading state.
317
-
318
- .. versionadded:: 2.7
319
- """
320
- return self ._response_message_loading
321
-
322
- def is_ephemeral (self ) -> bool :
323
- """Indicates whether the response message is ephemeral.
324
-
325
- This might be useful for determining if the message was forced to be ephemeral.
326
-
327
- .. versionadded:: 2.7
328
- """
329
- return self ._response_message_ephemeral
330
-
331
320
@utils .cached_slot_property ("_cs_channel" )
332
321
@utils .deprecated ("Interaction.channel" , "2.7" , stacklevel = 4 )
333
322
def cached_channel (self ) -> InteractionChannel | None :
@@ -895,7 +884,7 @@ async def pong(self) -> None:
895
884
)
896
885
)
897
886
self ._responded = True
898
- self ._process_callback_response (callback_response )
887
+ await self ._process_callback_response (callback_response )
899
888
900
889
async def _process_callback_response (
901
890
self , callback_response : InteractionCallbackResponse
@@ -911,12 +900,7 @@ async def _process_callback_response(
911
900
message = InteractionMessage (state = state , channel = channel , data = callback_response ["resource" ]["message" ]) # type: ignore
912
901
self ._parent ._original_response = message
913
902
914
- self ._parent ._response_message_ephemeral = callback_response ["interaction" ].get (
915
- "response_message_ephemeral" , False
916
- )
917
- self ._parent ._response_message_loading = callback_response ["interaction" ].get (
918
- "response_message_loading" , False
919
- )
903
+ self ._parent .callback = InteractionCallback (callback_response ["interaction" ])
920
904
921
905
async def send_message (
922
906
self ,
@@ -1294,7 +1278,7 @@ async def send_autocomplete_result(
1294
1278
)
1295
1279
1296
1280
self ._responded = True
1297
- self ._process_callback_response (callback_response )
1281
+ await self ._process_callback_response (callback_response )
1298
1282
1299
1283
async def send_modal (self , modal : Modal ) -> Interaction :
1300
1284
"""|coro|
@@ -1333,7 +1317,7 @@ async def send_modal(self, modal: Modal) -> Interaction:
1333
1317
)
1334
1318
)
1335
1319
self ._responded = True
1336
- self ._process_callback_response (callback_response )
1320
+ await self ._process_callback_response (callback_response )
1337
1321
self ._parent ._state .store_modal (modal , self ._parent .user .id )
1338
1322
return self ._parent
1339
1323
@@ -1372,7 +1356,7 @@ async def premium_required(self) -> Interaction:
1372
1356
)
1373
1357
)
1374
1358
self ._responded = True
1375
- self ._process_callback_response (callback_response )
1359
+ await self ._process_callback_response (callback_response )
1376
1360
return self ._parent
1377
1361
1378
1362
async def _locked_response (self , coro : Coroutine [Any , Any , Any ]) -> Any :
@@ -1718,3 +1702,26 @@ def guild(self) -> Guild | None:
1718
1702
if not self .guild_id :
1719
1703
return None
1720
1704
return self ._state ._get_guild (self .guild_id )
1705
+
1706
+
1707
+ class InteractionCallback :
1708
+ """Information about the status of the interaction response.
1709
+
1710
+ .. versionadded:: 2.7
1711
+ """
1712
+ def __init__ (self , data : InteractionCallbackPayload ):
1713
+ self ._response_message_loading : bool = data .get ("response_message_loading" , False )
1714
+ self ._response_message_ephemeral : bool = data .get ("response_message_ephemeral" , False )
1715
+
1716
+ def is_loading (self ) -> bool :
1717
+ """Indicates whether the response message is in a loading state.
1718
+ """
1719
+ return self ._response_message_loading
1720
+
1721
+ def is_ephemeral (self ) -> bool :
1722
+ """Indicates whether the response message is ephemeral.
1723
+
1724
+ This might be useful for determining if the message was forced to be ephemeral.
1725
+ """
1726
+ return self ._response_message_ephemeral
1727
+
0 commit comments