mirror of
https://github.com/Rapptz/discord.py.git
synced 2026-03-05 03:02:49 +00:00
Remove old workaround to /callback not having a return type
The old code needed a workaround using interaction_id to differentiate between multiple instances being reused since they would all go into the `None` key. Since /callback now returns a proper message_id this could be used as a key instead of None. From testing, it seems this is true for both edit_message and send_message responses.
This commit is contained in:
@@ -615,7 +615,7 @@ class Interaction(Generic[ClientT]):
|
||||
state = _InteractionMessageState(self, self._state)
|
||||
message = InteractionMessage(state=state, channel=self.channel, data=data) # type: ignore
|
||||
if view and not view.is_finished() and view.is_dispatchable():
|
||||
self._state.store_view(view, message.id, interaction_id=self.id)
|
||||
self._state.store_view(view, message.id)
|
||||
return message
|
||||
|
||||
async def delete_original_response(self) -> None:
|
||||
@@ -1082,7 +1082,7 @@ class InteractionResponse(Generic[ClientT]):
|
||||
)
|
||||
|
||||
http = parent._state.http
|
||||
response = await adapter.create_interaction_response(
|
||||
data = await adapter.create_interaction_response(
|
||||
parent.id,
|
||||
parent.token,
|
||||
session=parent._session,
|
||||
@@ -1090,17 +1090,19 @@ class InteractionResponse(Generic[ClientT]):
|
||||
proxy_auth=http.proxy_auth,
|
||||
params=params,
|
||||
)
|
||||
self._response_type = InteractionResponseType.channel_message
|
||||
response = InteractionCallbackResponse(
|
||||
data=data,
|
||||
parent=self._parent,
|
||||
state=self._parent._state,
|
||||
type=self._response_type,
|
||||
)
|
||||
|
||||
if view is not MISSING and not view.is_finished():
|
||||
if ephemeral and view.timeout is None:
|
||||
view.timeout = 15 * 60.0
|
||||
|
||||
# If the interaction type isn't an application command then there's no way
|
||||
# to obtain this interaction_id again, so just default to None
|
||||
entity_id = parent.id if parent.type is InteractionType.application_command else None
|
||||
self._parent._state.store_view(view, entity_id)
|
||||
|
||||
self._response_type = InteractionResponseType.channel_message
|
||||
self._parent._state.store_view(view, response.message_id)
|
||||
|
||||
if delete_after is not None:
|
||||
|
||||
@@ -1113,12 +1115,7 @@ class InteractionResponse(Generic[ClientT]):
|
||||
|
||||
asyncio.create_task(inner_call())
|
||||
|
||||
return InteractionCallbackResponse(
|
||||
data=response,
|
||||
parent=self._parent,
|
||||
state=self._parent._state,
|
||||
type=self._response_type,
|
||||
)
|
||||
return response
|
||||
|
||||
async def edit_message(
|
||||
self,
|
||||
@@ -1205,12 +1202,8 @@ class InteractionResponse(Generic[ClientT]):
|
||||
state = parent._state
|
||||
if msg is not None:
|
||||
message_id = msg.id
|
||||
# If this was invoked via an application command then we can use its original interaction ID
|
||||
# Since this is used as a cache key for view updates
|
||||
original_interaction_id = msg.interaction_metadata.id if msg.interaction_metadata is not None else None
|
||||
else:
|
||||
message_id = None
|
||||
original_interaction_id = None
|
||||
|
||||
if parent.type not in (InteractionType.component, InteractionType.modal_submit):
|
||||
return
|
||||
@@ -1238,7 +1231,7 @@ class InteractionResponse(Generic[ClientT]):
|
||||
)
|
||||
|
||||
http = parent._state.http
|
||||
response = await adapter.create_interaction_response(
|
||||
data = await adapter.create_interaction_response(
|
||||
parent.id,
|
||||
parent.token,
|
||||
session=parent._session,
|
||||
@@ -1246,11 +1239,16 @@ class InteractionResponse(Generic[ClientT]):
|
||||
proxy_auth=http.proxy_auth,
|
||||
params=params,
|
||||
)
|
||||
self._response_type = InteractionResponseType.message_update
|
||||
response = InteractionCallbackResponse(
|
||||
data=data,
|
||||
parent=self._parent,
|
||||
state=self._parent._state,
|
||||
type=self._response_type,
|
||||
)
|
||||
|
||||
if view and not view.is_finished() and view.is_dispatchable():
|
||||
state.store_view(view, message_id, interaction_id=original_interaction_id)
|
||||
|
||||
self._response_type = InteractionResponseType.message_update
|
||||
state.store_view(view, message_id or response.message_id)
|
||||
|
||||
if delete_after is not None:
|
||||
|
||||
@@ -1263,12 +1261,7 @@ class InteractionResponse(Generic[ClientT]):
|
||||
|
||||
asyncio.create_task(inner_call())
|
||||
|
||||
return InteractionCallbackResponse(
|
||||
data=response,
|
||||
parent=self._parent,
|
||||
state=self._parent._state,
|
||||
type=self._response_type,
|
||||
)
|
||||
return response
|
||||
|
||||
async def send_modal(self, modal: Modal, /) -> InteractionCallbackResponse[ClientT]:
|
||||
"""|coro|
|
||||
|
||||
Reference in New Issue
Block a user