Skip to content

Commit

Permalink
Update interactions.py
Browse files Browse the repository at this point in the history
  • Loading branch information
plun1331 authored Oct 24, 2021
1 parent 2bbf063 commit ff7fe71
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions discord/interactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,18 +396,14 @@ def is_done(self) -> bool:

async def defer(self, *, ephemeral: bool = False) -> None:
"""|coro|
Defers the interaction response.
This is typically used when the interaction is acknowledged
and a secondary action will be done later.
Parameters
-----------
ephemeral: :class:`bool`
Indicates whether the deferred message will eventually be ephemeral.
This only applies for interactions of type :attr:`InteractionType.application_command`.
If ``True`` for interactions of type :attr:`InteractionType.component`, this will send an ephemeral 'bot is thinking' message in the channel.
Raises
-------
HTTPException
Expand All @@ -416,20 +412,24 @@ async def defer(self, *, ephemeral: bool = False) -> None:
This interaction has already been responded to before.
"""
if self._responded:
raise InteractionResponded(self._parent)
raise discord.InteractionResponded(self._parent)

defer_type: int = 0
data: Optional[Dict[str, Any]] = None
data = None
parent = self._parent
if parent.type is InteractionType.component:
defer_type = InteractionResponseType.deferred_message_update.value
elif parent.type is InteractionType.application_command:
defer_type = InteractionResponseType.deferred_channel_message.value
if parent.type is discord.InteractionType.component:
if ephemeral:
data = {'flags': 64}
defer_type = discord.InteractionResponseType.deferred_channel_message.value
else:
defer_type = discord.InteractionResponseType.deferred_message_update.value
elif parent.type is discord.InteractionType.application_command:
defer_type = discord.InteractionResponseType.deferred_channel_message.value
if ephemeral:
data = {'flags': 64}

if defer_type:
adapter = async_context.get()
adapter = discord.webhook.async_.async_context.get()
await adapter.create_interaction_response(
parent.id, parent.token, session=parent._session, type=defer_type, data=data
)
Expand Down Expand Up @@ -840,4 +840,4 @@ async def inner_call(delay: float = delay):

asyncio.create_task(inner_call())
else:
await self._state._interaction.delete_original_message()
await self._state._interaction.delete_original_message()

0 comments on commit ff7fe71

Please sign in to comment.