Browse Source

Add InteractionResponse.type property

pull/8302/head
Mikey 3 years ago
committed by GitHub
parent
commit
c4e09acff8
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 35
      discord/interactions.py

35
discord/interactions.py

@ -508,20 +508,25 @@ class InteractionResponse:
""" """
__slots__: Tuple[str, ...] = ( __slots__: Tuple[str, ...] = (
'_responded', '_response_type',
'_parent', '_parent',
) )
def __init__(self, parent: Interaction): def __init__(self, parent: Interaction):
self._parent: Interaction = parent self._parent: Interaction = parent
self._responded: bool = False self._response_type: Optional[InteractionResponseType] = None
def is_done(self) -> bool: def is_done(self) -> bool:
""":class:`bool`: Indicates whether an interaction response has been done before. """:class:`bool`: Indicates whether an interaction response has been done before.
An interaction can only be responded to once. An interaction can only be responded to once.
""" """
return self._responded return self._response_type is not None
@property
def type(self) -> Optional[InteractionResponseType]:
""":class:`InteractionResponseType`: The type of response that was sent, ``None`` if response is not done."""
return self._response_type
async def defer(self, *, ephemeral: bool = False, thinking: bool = False) -> None: async def defer(self, *, ephemeral: bool = False, thinking: bool = False) -> None:
"""|coro| """|coro|
@ -556,7 +561,7 @@ class InteractionResponse:
InteractionResponded InteractionResponded
This interaction has already been responded to before. This interaction has already been responded to before.
""" """
if self._responded: if self._response_type:
raise InteractionResponded(self._parent) raise InteractionResponded(self._parent)
defer_type: int = 0 defer_type: int = 0
@ -587,7 +592,7 @@ class InteractionResponse:
proxy_auth=http.proxy_auth, proxy_auth=http.proxy_auth,
params=params, params=params,
) )
self._responded = True self._response_type = InteractionResponseType(defer_type)
async def pong(self) -> None: async def pong(self) -> None:
"""|coro| """|coro|
@ -603,7 +608,7 @@ class InteractionResponse:
InteractionResponded InteractionResponded
This interaction has already been responded to before. This interaction has already been responded to before.
""" """
if self._responded: if self._response_type:
raise InteractionResponded(self._parent) raise InteractionResponded(self._parent)
parent = self._parent parent = self._parent
@ -619,7 +624,7 @@ class InteractionResponse:
proxy_auth=http.proxy_auth, proxy_auth=http.proxy_auth,
params=params, params=params,
) )
self._responded = True self._response_type = InteractionResponseType.pong
async def send_message( async def send_message(
self, self,
@ -678,7 +683,7 @@ class InteractionResponse:
InteractionResponded InteractionResponded
This interaction has already been responded to before. This interaction has already been responded to before.
""" """
if self._responded: if self._response_type:
raise InteractionResponded(self._parent) raise InteractionResponded(self._parent)
if ephemeral or suppress_embeds: if ephemeral or suppress_embeds:
@ -723,7 +728,7 @@ class InteractionResponse:
entity_id = parent.id if parent.type is InteractionType.application_command else None entity_id = parent.id if parent.type is InteractionType.application_command else None
self._parent._state.store_view(view, entity_id) self._parent._state.store_view(view, entity_id)
self._responded = True self._response_type = InteractionResponseType.channel_message
async def edit_message( async def edit_message(
self, self,
@ -773,7 +778,7 @@ class InteractionResponse:
InteractionResponded InteractionResponded
This interaction has already been responded to before. This interaction has already been responded to before.
""" """
if self._responded: if self._response_type:
raise InteractionResponded(self._parent) raise InteractionResponded(self._parent)
parent = self._parent parent = self._parent
@ -811,7 +816,7 @@ class InteractionResponse:
if view and not view.is_finished(): if view and not view.is_finished():
state.store_view(view, message_id) state.store_view(view, message_id)
self._responded = True self._response_type = InteractionResponseType.message_update
async def send_modal(self, modal: Modal, /) -> None: async def send_modal(self, modal: Modal, /) -> None:
"""|coro| """|coro|
@ -830,7 +835,7 @@ class InteractionResponse:
InteractionResponded InteractionResponded
This interaction has already been responded to before. This interaction has already been responded to before.
""" """
if self._responded: if self._response_type:
raise InteractionResponded(self._parent) raise InteractionResponded(self._parent)
parent = self._parent parent = self._parent
@ -849,7 +854,7 @@ class InteractionResponse:
) )
self._parent._state.store_view(modal) self._parent._state.store_view(modal)
self._responded = True self._response_type = InteractionResponseType.modal
async def autocomplete(self, choices: Sequence[Choice[ChoiceT]]) -> None: async def autocomplete(self, choices: Sequence[Choice[ChoiceT]]) -> None:
"""|coro| """|coro|
@ -870,7 +875,7 @@ class InteractionResponse:
InteractionResponded InteractionResponded
This interaction has already been responded to before. This interaction has already been responded to before.
""" """
if self._responded: if self._response_type:
raise InteractionResponded(self._parent) raise InteractionResponded(self._parent)
payload: Dict[str, Any] = { payload: Dict[str, Any] = {
@ -893,7 +898,7 @@ class InteractionResponse:
params=params, params=params,
) )
self._responded = True self._response_type = InteractionResponseType.autocomplete_result
class _InteractionMessageState: class _InteractionMessageState:

Loading…
Cancel
Save