Skip to content

Commit eccd10b

Browse files
committed
feat: add AlreadyResponded and update errors for defer
1 parent 328e89b commit eccd10b

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

interactions/client/errors.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"InteractionException",
4343
"InteractionMissingAccess",
4444
"AlreadyDeferred",
45+
"AlreadyResponded",
4546
"ForeignWebhookException",
4647
"EventLocationNotProvided",
4748
"VoiceAlreadyConnected",
@@ -385,10 +386,14 @@ def __init__(self, scope: "Snowflake_Type") -> None:
385386
super().__init__(err_msg)
386387

387388

388-
class AlreadyDeferred(BotException):
389+
class AlreadyDeferred(InteractionException):
389390
"""An interaction was already deferred, and you attempted to defer it again."""
390391

391392

393+
class AlreadyResponded(AlreadyDeferred):
394+
"""An interaction was already responded to, and you attempted to defer it"""
395+
396+
392397
class ForeignWebhookException(NaffException):
393398
"""Raised when you attempt to send using a webhook you did not create."""
394399

interactions/models/internal/context.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from interactions.models.internal.command import BaseCommand
1616
from interactions.client.mixins.modal import ModalMixin
1717

18-
from interactions.client.errors import HTTPException
18+
from interactions.client.errors import HTTPException, AlreadyDeferred, AlreadyResponded
1919
from interactions.client.mixins.send import SendMixin
2020
from interactions.models.discord.enums import (
2121
Permissions,
@@ -680,8 +680,10 @@ async def defer(self, *, ephemeral: bool = False, edit_origin: bool = False) ->
680680
ephemeral: Whether the interaction response should be ephemeral.
681681
edit_origin: Whether to edit the original message instead of sending a new one.
682682
"""
683-
if self.deferred or self.responded:
684-
raise RuntimeError("Interaction has already been responded to.")
683+
if self.deferred:
684+
raise AlreadyDeferred("Interaction has already been responded to.")
685+
if self.responded:
686+
raise AlreadyResponded("Interaction has already been responded to.")
685687

686688
payload = {
687689
"type": CallbackType.DEFERRED_UPDATE_MESSAGE

0 commit comments

Comments
 (0)