Allow deferring modal_submit interactions

This also adds a thinking boolean to toggle which type of deferring
is done when there can be ambiguity.
This commit is contained in:
Rapptz 2022-02-20 05:23:09 -05:00
parent 19c6687b55
commit af8e74d327

View File

@ -388,7 +388,7 @@ class InteractionResponse:
""" """
return self._responded return self._responded
async def defer(self, *, ephemeral: bool = False) -> None: async def defer(self, *, ephemeral: bool = False, thinking: bool = False) -> None:
"""|coro| """|coro|
Defers the interaction response. Defers the interaction response.
@ -396,11 +396,23 @@ class InteractionResponse:
This is typically used when the interaction is acknowledged This is typically used when the interaction is acknowledged
and a secondary action will be done later. and a secondary action will be done later.
This is only supported with the following interaction types:
- :attr:`InteractionType.application_command`
- :attr:`InteractionType.component`
- :attr:`InteractionType.modal_submit`
Parameters Parameters
----------- -----------
ephemeral: :class:`bool` ephemeral: :class:`bool`
Indicates whether the deferred message will eventually be ephemeral. Indicates whether the deferred message will eventually be ephemeral.
This only applies for interactions of type :attr:`InteractionType.application_command`. This only applies for interactions of type :attr:`InteractionType.application_command`.
thinking: :class:`bool`
Indicates whether the deferred type should be :attr:`InteractionResponseType.deferred_channel_message`
instead of the default :attr:`InteractionResponseType.deferred_message_update` if both are valid.
In UI terms, this is represented as if the bot is thinking of a response. It is your responsibility to
eventually send a followup message via :attr:`Interaction.followup` to make this thinking state go away.
Application commands (AKA Slash commands) cannot use :attr:`InteractionResponseType.deferred_message_update`.
Raises Raises
------- -------
@ -415,8 +427,12 @@ class InteractionResponse:
defer_type: int = 0 defer_type: int = 0
data: Optional[Dict[str, Any]] = None data: Optional[Dict[str, Any]] = None
parent = self._parent parent = self._parent
if parent.type is InteractionType.component: if parent.type is InteractionType.component or parent.type is InteractionType.modal_submit:
defer_type = InteractionResponseType.deferred_message_update.value defer_type = (
InteractionResponseType.deferred_channel_message.value
if thinking
else InteractionResponseType.deferred_message_update.value
)
elif parent.type is InteractionType.application_command: elif parent.type is InteractionType.application_command:
defer_type = InteractionResponseType.deferred_channel_message.value defer_type = InteractionResponseType.deferred_channel_message.value
if ephemeral: if ephemeral: