mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-07-07 02:21:54 +00:00
Raise an exception if an interaction has been responded before
Fix #7153
This commit is contained in:
parent
b7b75e2b1f
commit
7ca90874b9
@ -36,6 +36,7 @@ __all__ = (
|
|||||||
'LoginFailure',
|
'LoginFailure',
|
||||||
'ConnectionClosed',
|
'ConnectionClosed',
|
||||||
'PrivilegedIntentsRequired',
|
'PrivilegedIntentsRequired',
|
||||||
|
'InteractionResponded',
|
||||||
)
|
)
|
||||||
|
|
||||||
class DiscordException(Exception):
|
class DiscordException(Exception):
|
||||||
@ -213,3 +214,21 @@ class PrivilegedIntentsRequired(ClientException):
|
|||||||
'and explicitly enable the privileged intents within your application\'s page. If this is not ' \
|
'and explicitly enable the privileged intents within your application\'s page. If this is not ' \
|
||||||
'possible, then consider disabling the privileged intents instead.'
|
'possible, then consider disabling the privileged intents instead.'
|
||||||
super().__init__(msg % shard_id)
|
super().__init__(msg % shard_id)
|
||||||
|
|
||||||
|
class InteractionResponded(ClientException):
|
||||||
|
"""Exception that's raised when sending another interaction response using
|
||||||
|
:class:`InteractionResponse` when one has already been done before.
|
||||||
|
|
||||||
|
An interaction can only respond once.
|
||||||
|
|
||||||
|
.. versionadded:: 2.0
|
||||||
|
|
||||||
|
Attributes
|
||||||
|
-----------
|
||||||
|
interaction: :class:`Interaction`
|
||||||
|
The interaction that's already been responded to.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, interaction):
|
||||||
|
self.interaction = interaction
|
||||||
|
super().__init__('This interaction has already been responded to before')
|
||||||
|
@ -30,6 +30,7 @@ from typing import Any, Dict, List, Optional, TYPE_CHECKING, Tuple, Union
|
|||||||
|
|
||||||
from . import utils
|
from . import utils
|
||||||
from .enums import try_enum, InteractionType, InteractionResponseType
|
from .enums import try_enum, InteractionType, InteractionResponseType
|
||||||
|
from .errors import InteractionResponded
|
||||||
|
|
||||||
from .user import User
|
from .user import User
|
||||||
from .member import Member
|
from .member import Member
|
||||||
@ -189,6 +190,13 @@ class InteractionResponse:
|
|||||||
self._parent: Interaction = parent
|
self._parent: Interaction = parent
|
||||||
self._responded: bool = False
|
self._responded: bool = False
|
||||||
|
|
||||||
|
def is_done(self) -> bool:
|
||||||
|
""":class:`bool`: Indicates whether an interaction response has been done before.
|
||||||
|
|
||||||
|
An interaction can only be responded to once.
|
||||||
|
"""
|
||||||
|
return self._responded
|
||||||
|
|
||||||
async def defer(self, *, ephemeral: bool = False) -> None:
|
async def defer(self, *, ephemeral: bool = False) -> None:
|
||||||
"""|coro|
|
"""|coro|
|
||||||
|
|
||||||
@ -207,9 +215,11 @@ class InteractionResponse:
|
|||||||
-------
|
-------
|
||||||
HTTPException
|
HTTPException
|
||||||
Deferring the interaction failed.
|
Deferring the interaction failed.
|
||||||
|
InteractionResponsed
|
||||||
|
This interaction has already been responded to before.
|
||||||
"""
|
"""
|
||||||
if self._responded:
|
if self._responded:
|
||||||
return
|
raise InteractionResponded(self._parent)
|
||||||
|
|
||||||
defer_type: int = 0
|
defer_type: int = 0
|
||||||
data: Optional[Dict[str, Any]] = None
|
data: Optional[Dict[str, Any]] = None
|
||||||
@ -239,9 +249,11 @@ class InteractionResponse:
|
|||||||
-------
|
-------
|
||||||
HTTPException
|
HTTPException
|
||||||
Ponging the interaction failed.
|
Ponging the interaction failed.
|
||||||
|
InteractionResponsed
|
||||||
|
This interaction has already been responded to before.
|
||||||
"""
|
"""
|
||||||
if self._responded:
|
if self._responded:
|
||||||
return
|
raise InteractionResponded(self._parent)
|
||||||
|
|
||||||
parent = self._parent
|
parent = self._parent
|
||||||
if parent.type is InteractionType.ping:
|
if parent.type is InteractionType.ping:
|
||||||
@ -292,9 +304,11 @@ class InteractionResponse:
|
|||||||
You specified both ``embed`` and ``embeds``.
|
You specified both ``embed`` and ``embeds``.
|
||||||
ValueError
|
ValueError
|
||||||
The length of ``embeds`` was invalid.
|
The length of ``embeds`` was invalid.
|
||||||
|
InteractionResponsed
|
||||||
|
This interaction has already been responded to before.
|
||||||
"""
|
"""
|
||||||
if self._responded:
|
if self._responded:
|
||||||
return
|
raise InteractionResponded(self._parent)
|
||||||
|
|
||||||
payload: Dict[str, Any] = {
|
payload: Dict[str, Any] = {
|
||||||
'tts': tts,
|
'tts': tts,
|
||||||
@ -374,9 +388,11 @@ class InteractionResponse:
|
|||||||
Editing the message failed.
|
Editing the message failed.
|
||||||
TypeError
|
TypeError
|
||||||
You specified both ``embed`` and ``embeds``.
|
You specified both ``embed`` and ``embeds``.
|
||||||
|
InteractionResponsed
|
||||||
|
This interaction has already been responded to before.
|
||||||
"""
|
"""
|
||||||
if self._responded:
|
if self._responded:
|
||||||
return
|
raise InteractionResponded(self._parent)
|
||||||
|
|
||||||
parent = self._parent
|
parent = self._parent
|
||||||
msg = parent.message
|
msg = parent.message
|
||||||
|
@ -3862,6 +3862,8 @@ The following exceptions are thrown by the library.
|
|||||||
|
|
||||||
.. autoexception:: PrivilegedIntentsRequired
|
.. autoexception:: PrivilegedIntentsRequired
|
||||||
|
|
||||||
|
.. autoexception:: InteractionResponded
|
||||||
|
|
||||||
.. autoexception:: discord.opus.OpusError
|
.. autoexception:: discord.opus.OpusError
|
||||||
|
|
||||||
.. autoexception:: discord.opus.OpusNotLoaded
|
.. autoexception:: discord.opus.OpusNotLoaded
|
||||||
@ -3879,6 +3881,7 @@ Exception Hierarchy
|
|||||||
- :exc:`LoginFailure`
|
- :exc:`LoginFailure`
|
||||||
- :exc:`ConnectionClosed`
|
- :exc:`ConnectionClosed`
|
||||||
- :exc:`PrivilegedIntentsRequired`
|
- :exc:`PrivilegedIntentsRequired`
|
||||||
|
- :exc:`InteractionResponded`
|
||||||
- :exc:`NoMoreItems`
|
- :exc:`NoMoreItems`
|
||||||
- :exc:`GatewayNotFound`
|
- :exc:`GatewayNotFound`
|
||||||
- :exc:`HTTPException`
|
- :exc:`HTTPException`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user