Skip to content

Commit 253e8be

Browse files
authored
Allow component response to be ignored (#268)
* Added `ignore` param to ComponentContext.defer * Added IncorrectFormat error at ComponentContext.defer * Applied pre_push.py result
1 parent 20f7afe commit 253e8be

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

discord_slash/context.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -466,30 +466,40 @@ def __init__(
466466
if self.component_type == 3:
467467
self.selected_options = _json["data"].get("values", [])
468468

469-
async def defer(self, hidden: bool = False, edit_origin: bool = False):
469+
async def defer(self, hidden: bool = False, edit_origin: bool = False, ignore: bool = False):
470470
"""
471471
'Defers' the response, showing a loading state to the user
472472
473-
:param hidden: Whether the deferred response should be ephemeral . Default ``False``.
473+
:param hidden: Whether the deferred response should be ephemeral. Default ``False``.
474474
:param edit_origin: Whether the type is editing the origin message. If ``False``, the deferred response will be for a follow up message. Defaults ``False``.
475+
:param ignore: Whether to just ignore and not edit or send response. Using this can avoid showing interaction loading state. Default ``False``.
475476
"""
476477
if self.deferred or self.responded:
477478
raise error.AlreadyResponded("You have already responded to this command!")
478479

479-
base = {"type": 6 if edit_origin else 5}
480+
base = {"type": 6 if edit_origin or ignore else 5}
481+
482+
if edit_origin and ignore:
483+
raise error.IncorrectFormat("'edit_origin' and 'ignore' are mutually exclusive")
480484

481485
if hidden:
482486
if edit_origin:
483487
raise error.IncorrectFormat(
484488
"'hidden' and 'edit_origin' flags are mutually exclusive"
485489
)
486-
base["data"] = {"flags": 64}
487-
self._deferred_hidden = True
490+
elif ignore:
491+
self._deferred_hidden = True
492+
else:
493+
base["data"] = {"flags": 64}
494+
self._deferred_hidden = True
488495

489496
self._deferred_edit_origin = edit_origin
490497

491498
await self._http.post_initial_response(base, self.interaction_id, self._token)
492-
self.deferred = True
499+
self.deferred = not ignore
500+
501+
if ignore:
502+
self.responded = True
493503

494504
async def send(
495505
self,

0 commit comments

Comments
 (0)