Skip to content

Commit

Permalink
Fix deferring (#1379)
Browse files Browse the repository at this point in the history
Update interactions.py
  • Loading branch information
plun1331 authored May 24, 2022
1 parent d64b65f commit 7c4a7b0
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions discord/interactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,20 +490,26 @@ def is_done(self) -> bool:
"""
return self._responded

async def defer(self, *, ephemeral: bool = False) -> None:
async def defer(self, *, ephemeral: bool = False, invisible: bool = True) -> None:
"""|coro|
Defers the interaction response.
This is typically used when the interaction is acknowledged
and a secondary action will be done later.
This is can only be used with the following interaction types
- :attr:`InteractionType.application_command`
- :attr:`InteractionType.component`
- :attr:`InteractionType.modal_submit`
Parameters
-----------
ephemeral: :class:`bool`
Indicates whether the deferred message will eventually be ephemeral.
If ``True`` for interactions of type :attr:`InteractionType.component`, this will defer ephemerally.
This only applies to :attr:`InteractionType.application_command` interactions, or if ``invisible`` is ``False``.
invisible: :class:`bool`
Indicates whether the deferred type should be 'invisible' (:attr:`InteractionResponseType.deferred_message_update`)
instead of 'thinking' (:attr:`InteractionResponseType.deferred_channel_message`).
In the Discord UI, this is represented as the bot thinking of a response. You must
eventually send a followup message via :attr:`Interaction.followup` to make this thinking state go away.
This parameter does not apply to interactions of type :attr:`InteractionType.application_command`.
Raises
-------
HTTPException
Expand All @@ -517,16 +523,18 @@ async def defer(self, *, ephemeral: bool = False) -> None:
defer_type: int = 0
data: Optional[Dict[str, Any]] = None
parent = self._parent
if parent.type is InteractionType.component:
if ephemeral:
data = {"flags": 64}
defer_type = InteractionResponseType.deferred_channel_message.value
else:
defer_type = InteractionResponseType.deferred_message_update.value
elif parent.type in (InteractionType.application_command, InteractionType.modal_submit):
if parent.type is InteractionType.component or parent.type is InteractionType.modal_submit:
defer_type = (
InteractionResponseType.deferred_message_update.value
if invisible
else InteractionResponseType.deferred_channel_message.value
)
if not invisible and ephemeral:
data = {'flags': 64}
elif parent.type is InteractionType.application_command:
defer_type = InteractionResponseType.deferred_channel_message.value
if ephemeral:
data = {"flags": 64}
data = {'flags': 64}

if defer_type:
adapter = async_context.get()
Expand Down

0 comments on commit 7c4a7b0

Please sign in to comment.