From 51e40afaa2ec240cc04e2689d2afd6d79f36be4e Mon Sep 17 00:00:00 2001 From: Ice Wolfy Date: Mon, 10 Feb 2025 21:53:35 -0500 Subject: [PATCH 1/9] feat: Implement with_response For Interaction Callbacks --- discord/interactions.py | 48 +++++++++++++++++++++++++++++++---- discord/types/interactions.py | 23 +++++++++++++++++ discord/webhook/async_.py | 5 ++++ 3 files changed, 71 insertions(+), 5 deletions(-) diff --git a/discord/interactions.py b/discord/interactions.py index 57628f4691..28b3d8d8ad 100644 --- a/discord/interactions.py +++ b/discord/interactions.py @@ -81,7 +81,7 @@ from .poll import Poll from .state import ConnectionState from .threads import Thread - from .types.interactions import Interaction as InteractionPayload + from .types.interactions import Interaction as InteractionPayload, InteractionCallbackResponse from .types.interactions import InteractionData from .types.interactions import InteractionMetadata as InteractionMetadataPayload from .types.interactions import MessageInteraction as MessageInteractionPayload @@ -129,6 +129,7 @@ class Interaction: The user or member that sent the interaction. Will be `None` in PING interactions. message: Optional[:class:`Message`] The message that sent this interaction. + This is updated to the message object of the response after responding by sending or editing a message. token: :class:`str` The token to continue the interaction. These are valid for 15 minutes. @@ -185,12 +186,16 @@ class Interaction: "_cs_response", "_cs_followup", "_cs_channel", + "_response_message_loading", + "_response_message_ephemeral", ) def __init__(self, *, data: InteractionPayload, state: ConnectionState): self._state: ConnectionState = state self._session: ClientSession = state.http._HTTPClient__session self._original_response: InteractionMessage | None = None + self._response_message_loading: bool = False + self._response_message_ephemeral: bool = False self._from_data(data) def _from_data(self, data: InteractionPayload): @@ -308,6 +313,22 @@ def is_component(self) -> bool: """Indicates whether the interaction is a message component.""" return self.type == InteractionType.component + def is_loading(self) -> bool: + """Indicates whether the response message is in a loading state. + + .. versionadded:: 2.7 + """ + return self._response_message_loading + + def is_ephemeral(self) -> bool: + """Indicates whether the response message is ephemeral. + + This might be useful for determining if the message was forced to be ephemeral. + + .. versionadded:: 2.7 + """ + return self._response_message_ephemeral + @utils.cached_slot_property("_cs_channel") @utils.deprecated("Interaction.channel", "2.7", stacklevel=4) def cached_channel(self) -> InteractionChannel | None: @@ -871,6 +892,19 @@ async def pong(self) -> None: ) self._responded = True + async def _process_callback_response(self, callback_response: InteractionCallbackResponse): + if callback_response.get("resource") and callback_response["resource"].get("message"): + # TODO: fix later to not raise? + channel = self._parent.channel + if channel is None: + raise ClientException("Channel for message could not be resolved") + state = _InteractionMessageState(self._parent, self._parent._state) + message = InteractionMessage(state=state, channel=channel, data=callback_response["resource"]["message"]) # type: ignore + self._parent._original_response = message + + self._parent._response_message_ephemeral = callback_response["interaction"].get("response_message_ephemeral", False) + self._parent._response_message_loading = callback_response["interaction"].get("response_message_loading", False) + async def send_message( self, content: Any | None = None, @@ -1007,7 +1041,7 @@ async def send_message( adapter = async_context.get() http = parent._state.http try: - await self._locked_response( + callback_response: InteractionCallbackResponse = await self._locked_response( adapter.create_interaction_response( parent.id, parent.token, @@ -1031,6 +1065,8 @@ async def send_message( view.parent = self._parent self._parent._state.store_view(view) + await self._process_callback_response(callback_response) + self._responded = True if delete_after is not None: await self._parent.delete_original_response(delay=delete_after) @@ -1171,7 +1207,7 @@ async def edit_message( adapter = async_context.get() http = parent._state.http try: - await self._locked_response( + callback_response: InteractionCallbackResponse = await self._locked_response( adapter.create_interaction_response( parent.id, parent.token, @@ -1192,6 +1228,8 @@ async def edit_message( view.message = msg state.store_view(view, message_id) + await self._process_callback_response(callback_response) + self._responded = True if delete_after is not None: await self._parent.delete_original_response(delay=delete_after) @@ -1319,7 +1357,7 @@ async def premium_required(self) -> Interaction: self._responded = True return self._parent - async def _locked_response(self, coro: Coroutine[Any, Any, Any]) -> None: + async def _locked_response(self, coro: Coroutine[Any, Any, Any]) -> Any: """|coro| Wraps a response and makes sure that it's locked while executing. @@ -1338,7 +1376,7 @@ async def _locked_response(self, coro: Coroutine[Any, Any, Any]) -> None: if self.is_done(): coro.close() # cleanup un-awaited coroutine raise InteractionResponded(self._parent) - await coro + return await coro class _InteractionMessageState: diff --git a/discord/types/interactions.py b/discord/types/interactions.py index 37904a580a..c3562d0abd 100644 --- a/discord/types/interactions.py +++ b/discord/types/interactions.py @@ -272,3 +272,26 @@ class EditApplicationCommand(TypedDict): _StringApplicationIntegrationType = Literal["0", "1"] AuthorizingIntegrationOwners = Dict[_StringApplicationIntegrationType, Snowflake] + + +class InteractionCallbackResponse(TypedDict): + interaction: InteractionCallback + resource: NotRequired[InteractionCallbackResource] + + +class InteractionCallback(TypedDict): + id: Snowflake + type: InteractionType + activity_instance_id: NotRequired[str] + response_message_id: NotRequired[Snowflake] + response_message_loading: NotRequired[bool] + response_message_ephemeral: NotRequired[bool] + + +class InteractionCallbackResource(TypedDict): + type: InteractionResponseType + # This is not fully typed as activities are out of scope + activity_instance: NotRequired[dict] + message: NotRequired[Message] + + diff --git a/discord/webhook/async_.py b/discord/webhook/async_.py index 4b87a7e0f3..ef0e80bbee 100644 --- a/discord/webhook/async_.py +++ b/discord/webhook/async_.py @@ -537,6 +537,10 @@ def create_interaction_response( webhook_token=token, ) + params: dict[str, Any] = { + "with_response": True, + } + return self.request( route, session=session, @@ -544,6 +548,7 @@ def create_interaction_response( proxy_auth=proxy_auth, files=files, multipart=form, + params=params, ) def get_original_interaction_response( From 0b4aa8cfc1d67a607af7ed72cb8c262561d7e10a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 11 Feb 2025 03:08:14 +0000 Subject: [PATCH 2/9] style(pre-commit): auto fixes from pre-commit.com hooks --- discord/interactions.py | 64 +++++++++++++++++++++-------------- discord/types/interactions.py | 2 -- 2 files changed, 38 insertions(+), 28 deletions(-) diff --git a/discord/interactions.py b/discord/interactions.py index 28b3d8d8ad..058ccc8c94 100644 --- a/discord/interactions.py +++ b/discord/interactions.py @@ -81,8 +81,8 @@ from .poll import Poll from .state import ConnectionState from .threads import Thread - from .types.interactions import Interaction as InteractionPayload, InteractionCallbackResponse - from .types.interactions import InteractionData + from .types.interactions import Interaction as InteractionPayload + from .types.interactions import InteractionCallbackResponse, InteractionData from .types.interactions import InteractionMetadata as InteractionMetadataPayload from .types.interactions import MessageInteraction as MessageInteractionPayload from .ui.modal import Modal @@ -892,8 +892,12 @@ async def pong(self) -> None: ) self._responded = True - async def _process_callback_response(self, callback_response: InteractionCallbackResponse): - if callback_response.get("resource") and callback_response["resource"].get("message"): + async def _process_callback_response( + self, callback_response: InteractionCallbackResponse + ): + if callback_response.get("resource") and callback_response["resource"].get( + "message" + ): # TODO: fix later to not raise? channel = self._parent.channel if channel is None: @@ -902,8 +906,12 @@ async def _process_callback_response(self, callback_response: InteractionCallbac message = InteractionMessage(state=state, channel=channel, data=callback_response["resource"]["message"]) # type: ignore self._parent._original_response = message - self._parent._response_message_ephemeral = callback_response["interaction"].get("response_message_ephemeral", False) - self._parent._response_message_loading = callback_response["interaction"].get("response_message_loading", False) + self._parent._response_message_ephemeral = callback_response["interaction"].get( + "response_message_ephemeral", False + ) + self._parent._response_message_loading = callback_response["interaction"].get( + "response_message_loading", False + ) async def send_message( self, @@ -1041,16 +1049,18 @@ async def send_message( adapter = async_context.get() http = parent._state.http try: - callback_response: InteractionCallbackResponse = await self._locked_response( - adapter.create_interaction_response( - parent.id, - parent.token, - session=parent._session, - type=InteractionResponseType.channel_message.value, - proxy=http.proxy, - proxy_auth=http.proxy_auth, - data=payload, - files=files, + callback_response: InteractionCallbackResponse = ( + await self._locked_response( + adapter.create_interaction_response( + parent.id, + parent.token, + session=parent._session, + type=InteractionResponseType.channel_message.value, + proxy=http.proxy, + proxy_auth=http.proxy_auth, + data=payload, + files=files, + ) ) ) finally: @@ -1207,16 +1217,18 @@ async def edit_message( adapter = async_context.get() http = parent._state.http try: - callback_response: InteractionCallbackResponse = await self._locked_response( - adapter.create_interaction_response( - parent.id, - parent.token, - session=parent._session, - type=InteractionResponseType.message_update.value, - proxy=http.proxy, - proxy_auth=http.proxy_auth, - data=payload, - files=files, + callback_response: InteractionCallbackResponse = ( + await self._locked_response( + adapter.create_interaction_response( + parent.id, + parent.token, + session=parent._session, + type=InteractionResponseType.message_update.value, + proxy=http.proxy, + proxy_auth=http.proxy_auth, + data=payload, + files=files, + ) ) ) finally: diff --git a/discord/types/interactions.py b/discord/types/interactions.py index c3562d0abd..4c9f325987 100644 --- a/discord/types/interactions.py +++ b/discord/types/interactions.py @@ -293,5 +293,3 @@ class InteractionCallbackResource(TypedDict): # This is not fully typed as activities are out of scope activity_instance: NotRequired[dict] message: NotRequired[Message] - - From 04a0f27b316ad501b975870531d6f11293046446 Mon Sep 17 00:00:00 2001 From: Ice Wolfy Date: Mon, 10 Feb 2025 22:16:33 -0500 Subject: [PATCH 3/9] chore: Changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 647fc311be..a454bd6d75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,6 +49,9 @@ These changes are available on the `master` branch, but have not yet been releas ([#2579](https://github.com/Pycord-Development/pycord/pull/2579)) - Added new `Subscription` object and related methods/events. ([#2564](https://github.com/Pycord-Development/pycord/pull/2564)) +- Implemented `with_response` for interaction callbacks, adding `Interaction.is_loading()` + and `Interaction.is_ephemeral()`. + ([#2711](https://github.com/Pycord-Development/pycord/pull/2711)) ### Fixed From 9fae95a18a6599710202e2f662f5fb2f67005bec Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 11 Feb 2025 03:20:52 +0000 Subject: [PATCH 4/9] style(pre-commit): auto fixes from pre-commit.com hooks --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a454bd6d75..ca26d49860 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,8 +49,8 @@ These changes are available on the `master` branch, but have not yet been releas ([#2579](https://github.com/Pycord-Development/pycord/pull/2579)) - Added new `Subscription` object and related methods/events. ([#2564](https://github.com/Pycord-Development/pycord/pull/2564)) -- Implemented `with_response` for interaction callbacks, adding `Interaction.is_loading()` - and `Interaction.is_ephemeral()`. +- Implemented `with_response` for interaction callbacks, adding + `Interaction.is_loading()` and `Interaction.is_ephemeral()`. ([#2711](https://github.com/Pycord-Development/pycord/pull/2711)) ### Fixed From dbcb58cf12049381f3ccc460e8f294d047ff0f59 Mon Sep 17 00:00:00 2001 From: Ice Wolfy Date: Sat, 15 Feb 2025 00:39:59 -0500 Subject: [PATCH 5/9] fix: Set Correct URL Parameter Value --- discord/webhook/async_.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/webhook/async_.py b/discord/webhook/async_.py index ef0e80bbee..6ac4ea3042 100644 --- a/discord/webhook/async_.py +++ b/discord/webhook/async_.py @@ -538,7 +538,7 @@ def create_interaction_response( ) params: dict[str, Any] = { - "with_response": True, + "with_response": "true", } return self.request( From 426d991b98be0643957ed7cab53882a8cf369d21 Mon Sep 17 00:00:00 2001 From: Ice Wolfy Date: Sat, 15 Feb 2025 00:42:08 -0500 Subject: [PATCH 6/9] feat: Add Callback To All Responses --- discord/interactions.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/discord/interactions.py b/discord/interactions.py index 058ccc8c94..b152b1a8af 100644 --- a/discord/interactions.py +++ b/discord/interactions.py @@ -129,7 +129,6 @@ class Interaction: The user or member that sent the interaction. Will be `None` in PING interactions. message: Optional[:class:`Message`] The message that sent this interaction. - This is updated to the message object of the response after responding by sending or editing a message. token: :class:`str` The token to continue the interaction. These are valid for 15 minutes. @@ -846,7 +845,7 @@ async def defer(self, *, ephemeral: bool = False, invisible: bool = True) -> Non if defer_type: adapter = async_context.get() http = parent._state.http - await self._locked_response( + callback_response: InteractionCallbackResponse = await self._locked_response( adapter.create_interaction_response( parent.id, parent.token, @@ -858,6 +857,7 @@ async def defer(self, *, ephemeral: bool = False, invisible: bool = True) -> Non ) ) self._responded = True + await self._process_callback_response(callback_response) async def pong(self) -> None: """|coro| @@ -880,7 +880,7 @@ async def pong(self) -> None: if parent.type is InteractionType.ping: adapter = async_context.get() http = parent._state.http - await self._locked_response( + callback_response: InteractionCallbackResponse = await self._locked_response( adapter.create_interaction_response( parent.id, parent.token, @@ -891,6 +891,7 @@ async def pong(self) -> None: ) ) self._responded = True + self._process_callback_response(callback_response) async def _process_callback_response( self, callback_response: InteractionCallbackResponse @@ -1075,9 +1076,8 @@ async def send_message( view.parent = self._parent self._parent._state.store_view(view) - await self._process_callback_response(callback_response) - self._responded = True + await self._process_callback_response(callback_response) if delete_after is not None: await self._parent.delete_original_response(delay=delete_after) return self._parent @@ -1240,9 +1240,8 @@ async def edit_message( view.message = msg state.store_view(view, message_id) - await self._process_callback_response(callback_response) - self._responded = True + await self._process_callback_response(callback_response) if delete_after is not None: await self._parent.delete_original_response(delay=delete_after) @@ -1278,7 +1277,7 @@ async def send_autocomplete_result( adapter = async_context.get() http = parent._state.http - await self._locked_response( + callback_response: InteractionCallbackResponse = await self._locked_response( adapter.create_interaction_response( parent.id, parent.token, @@ -1291,6 +1290,7 @@ async def send_autocomplete_result( ) self._responded = True + self._process_callback_response(callback_response) async def send_modal(self, modal: Modal) -> Interaction: """|coro| @@ -1317,7 +1317,7 @@ async def send_modal(self, modal: Modal) -> Interaction: payload = modal.to_dict() adapter = async_context.get() http = parent._state.http - await self._locked_response( + callback_response: InteractionCallbackResponse = await self._locked_response( adapter.create_interaction_response( parent.id, parent.token, @@ -1329,6 +1329,7 @@ async def send_modal(self, modal: Modal) -> Interaction: ) ) self._responded = True + self._process_callback_response(callback_response) self._parent._state.store_modal(modal, self._parent.user.id) return self._parent @@ -1356,7 +1357,7 @@ async def premium_required(self) -> Interaction: adapter = async_context.get() http = parent._state.http - await self._locked_response( + callback_response: InteractionCallbackResponse = await self._locked_response( adapter.create_interaction_response( parent.id, parent.token, @@ -1367,6 +1368,7 @@ async def premium_required(self) -> Interaction: ) ) self._responded = True + self._process_callback_response(callback_response) return self._parent async def _locked_response(self, coro: Coroutine[Any, Any, Any]) -> Any: From 405cb7402f7224889d8da01a3436d856492b446c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 15 Feb 2025 05:50:50 +0000 Subject: [PATCH 7/9] style(pre-commit): auto fixes from pre-commit.com hooks --- discord/interactions.py | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/discord/interactions.py b/discord/interactions.py index b152b1a8af..024b407c94 100644 --- a/discord/interactions.py +++ b/discord/interactions.py @@ -845,15 +845,17 @@ async def defer(self, *, ephemeral: bool = False, invisible: bool = True) -> Non if defer_type: adapter = async_context.get() http = parent._state.http - callback_response: InteractionCallbackResponse = await self._locked_response( - adapter.create_interaction_response( - parent.id, - parent.token, - session=parent._session, - type=defer_type, - data=data, - proxy=http.proxy, - proxy_auth=http.proxy_auth, + callback_response: InteractionCallbackResponse = ( + await self._locked_response( + adapter.create_interaction_response( + parent.id, + parent.token, + session=parent._session, + type=defer_type, + data=data, + proxy=http.proxy, + proxy_auth=http.proxy_auth, + ) ) ) self._responded = True @@ -880,14 +882,16 @@ async def pong(self) -> None: if parent.type is InteractionType.ping: adapter = async_context.get() http = parent._state.http - callback_response: InteractionCallbackResponse = await self._locked_response( - adapter.create_interaction_response( - parent.id, - parent.token, - session=parent._session, - proxy=http.proxy, - proxy_auth=http.proxy_auth, - type=InteractionResponseType.pong.value, + callback_response: InteractionCallbackResponse = ( + await self._locked_response( + adapter.create_interaction_response( + parent.id, + parent.token, + session=parent._session, + proxy=http.proxy, + proxy_auth=http.proxy_auth, + type=InteractionResponseType.pong.value, + ) ) ) self._responded = True From 25823fdfd01743113e211c7750336f5803a6fcfa Mon Sep 17 00:00:00 2001 From: Ice Wolfy Date: Thu, 29 May 2025 18:37:31 -0500 Subject: [PATCH 8/9] refractor: Use A callback Parameter Of Interaction --- discord/interactions.py | 67 +++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/discord/interactions.py b/discord/interactions.py index 024b407c94..107198e2ca 100644 --- a/discord/interactions.py +++ b/discord/interactions.py @@ -60,6 +60,7 @@ "MessageInteraction", "InteractionMetadata", "AuthorizingIntegrationOwners", + "InteractionCallback" ) if TYPE_CHECKING: @@ -83,6 +84,7 @@ from .threads import Thread from .types.interactions import Interaction as InteractionPayload from .types.interactions import InteractionCallbackResponse, InteractionData + from .types.interactions import InteractionCallback as InteractionCallbackPayload from .types.interactions import InteractionMetadata as InteractionMetadataPayload from .types.interactions import MessageInteraction as MessageInteractionPayload from .ui.modal import Modal @@ -152,6 +154,11 @@ class Interaction: The context in which this command was executed. .. versionadded:: 2.6 + callback: Optional[:class:`InteractionCallback`] + The callback of the interaction. Contains information about the status of the interaction response. + Will be `None` until the interaction is responded to. + + .. versionadded:: 2.7 """ __slots__: tuple[str, ...] = ( @@ -172,6 +179,7 @@ class Interaction: "entitlements", "context", "authorizing_integration_owners", + "callback", "_channel_data", "_message_data", "_guild_data", @@ -185,16 +193,13 @@ class Interaction: "_cs_response", "_cs_followup", "_cs_channel", - "_response_message_loading", - "_response_message_ephemeral", ) def __init__(self, *, data: InteractionPayload, state: ConnectionState): self._state: ConnectionState = state self._session: ClientSession = state.http._HTTPClient__session self._original_response: InteractionMessage | None = None - self._response_message_loading: bool = False - self._response_message_ephemeral: bool = False + self.callback: InteractionCallback | None = None self._from_data(data) def _from_data(self, data: InteractionPayload): @@ -312,22 +317,6 @@ def is_component(self) -> bool: """Indicates whether the interaction is a message component.""" return self.type == InteractionType.component - def is_loading(self) -> bool: - """Indicates whether the response message is in a loading state. - - .. versionadded:: 2.7 - """ - return self._response_message_loading - - def is_ephemeral(self) -> bool: - """Indicates whether the response message is ephemeral. - - This might be useful for determining if the message was forced to be ephemeral. - - .. versionadded:: 2.7 - """ - return self._response_message_ephemeral - @utils.cached_slot_property("_cs_channel") @utils.deprecated("Interaction.channel", "2.7", stacklevel=4) def cached_channel(self) -> InteractionChannel | None: @@ -895,7 +884,7 @@ async def pong(self) -> None: ) ) self._responded = True - self._process_callback_response(callback_response) + await self._process_callback_response(callback_response) async def _process_callback_response( self, callback_response: InteractionCallbackResponse @@ -911,12 +900,7 @@ async def _process_callback_response( message = InteractionMessage(state=state, channel=channel, data=callback_response["resource"]["message"]) # type: ignore self._parent._original_response = message - self._parent._response_message_ephemeral = callback_response["interaction"].get( - "response_message_ephemeral", False - ) - self._parent._response_message_loading = callback_response["interaction"].get( - "response_message_loading", False - ) + self._parent.callback = InteractionCallback(callback_response["interaction"]) async def send_message( self, @@ -1294,7 +1278,7 @@ async def send_autocomplete_result( ) self._responded = True - self._process_callback_response(callback_response) + await self._process_callback_response(callback_response) async def send_modal(self, modal: Modal) -> Interaction: """|coro| @@ -1333,7 +1317,7 @@ async def send_modal(self, modal: Modal) -> Interaction: ) ) self._responded = True - self._process_callback_response(callback_response) + await self._process_callback_response(callback_response) self._parent._state.store_modal(modal, self._parent.user.id) return self._parent @@ -1372,7 +1356,7 @@ async def premium_required(self) -> Interaction: ) ) self._responded = True - self._process_callback_response(callback_response) + await self._process_callback_response(callback_response) return self._parent async def _locked_response(self, coro: Coroutine[Any, Any, Any]) -> Any: @@ -1718,3 +1702,26 @@ def guild(self) -> Guild | None: if not self.guild_id: return None return self._state._get_guild(self.guild_id) + + +class InteractionCallback: + """Information about the status of the interaction response. + + .. versionadded:: 2.7 + """ + def __init__(self, data: InteractionCallbackPayload): + self._response_message_loading: bool = data.get("response_message_loading", False) + self._response_message_ephemeral: bool = data.get("response_message_ephemeral", False) + + def is_loading(self) -> bool: + """Indicates whether the response message is in a loading state. + """ + return self._response_message_loading + + def is_ephemeral(self) -> bool: + """Indicates whether the response message is ephemeral. + + This might be useful for determining if the message was forced to be ephemeral. + """ + return self._response_message_ephemeral + From d3424987605cb1943a0b4847aac62935c47c0840 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 30 May 2025 20:30:26 +0000 Subject: [PATCH 9/9] style(pre-commit): auto fixes from pre-commit.com hooks --- CHANGELOG.md | 2 +- discord/interactions.py | 21 ++++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 99d783ed2a..00b6422e94 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,7 +55,7 @@ These changes are available on the `master` branch, but have not yet been releas ([#2714](https://github.com/Pycord-Development/pycord/pull/2714)) - Added the ability to pass a `datetime.time` object to `format_dt` ([#2747](https://github.com/Pycord-Development/pycord/pull/2747)) - - Implemented `with_response` for interaction callbacks, adding +- Implemented `with_response` for interaction callbacks, adding `Interaction.callback.is_loading()` and `Interaction.callback.is_ephemeral()`. ([#2711](https://github.com/Pycord-Development/pycord/pull/2711)) diff --git a/discord/interactions.py b/discord/interactions.py index 107198e2ca..fbb2542e39 100644 --- a/discord/interactions.py +++ b/discord/interactions.py @@ -60,7 +60,7 @@ "MessageInteraction", "InteractionMetadata", "AuthorizingIntegrationOwners", - "InteractionCallback" + "InteractionCallback", ) if TYPE_CHECKING: @@ -83,8 +83,8 @@ from .state import ConnectionState from .threads import Thread from .types.interactions import Interaction as InteractionPayload - from .types.interactions import InteractionCallbackResponse, InteractionData from .types.interactions import InteractionCallback as InteractionCallbackPayload + from .types.interactions import InteractionCallbackResponse, InteractionData from .types.interactions import InteractionMetadata as InteractionMetadataPayload from .types.interactions import MessageInteraction as MessageInteractionPayload from .ui.modal import Modal @@ -1707,15 +1707,19 @@ def guild(self) -> Guild | None: class InteractionCallback: """Information about the status of the interaction response. - .. versionadded:: 2.7 - """ + .. versionadded:: 2.7 + """ + def __init__(self, data: InteractionCallbackPayload): - self._response_message_loading: bool = data.get("response_message_loading", False) - self._response_message_ephemeral: bool = data.get("response_message_ephemeral", False) + self._response_message_loading: bool = data.get( + "response_message_loading", False + ) + self._response_message_ephemeral: bool = data.get( + "response_message_ephemeral", False + ) def is_loading(self) -> bool: - """Indicates whether the response message is in a loading state. - """ + """Indicates whether the response message is in a loading state.""" return self._response_message_loading def is_ephemeral(self) -> bool: @@ -1724,4 +1728,3 @@ def is_ephemeral(self) -> bool: This might be useful for determining if the message was forced to be ephemeral. """ return self._response_message_ephemeral -