Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 23 additions & 18 deletions interactions/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ async def edit(
payload["components"] = _components

payload = Message(**payload)
self.message = payload
self.message._client = self.client

return payload
Expand Down Expand Up @@ -321,13 +320,11 @@ class CommandContext(_Context):
:ivar Snowflake id: The ID of the interaction.
:ivar Snowflake application_id: The application ID of the interaction.
:ivar InteractionType type: The type of interaction.
:ivar str name: The name of the command in the interaction.
:ivar Optional[str] description?: The description of the command in the interaction.
:ivar Optional[List[Option]] options?: The options of the command in the interaction, if any.
:ivar InteractionData data: The application command data.
:ivar InteractionData data?: The application command data.
:ivar Optional[Union[Message, Member, User]] target: The target selected if this interaction is invoked as a context menu.
:ivar str token: The token of the interaction response.
:ivar Snowflake channel_id: The ID of the current channel.
:ivar Snowflake guild_id: The ID of the current guild.
:ivar Snowflake guild_id?: The ID of the current guild.
:ivar Snowflake channel_id?: The ID of the current channel.
:ivar bool responded: Whether an original response was made or not.
:ivar bool deferred: Whether the response was deferred or not.
:ivar str locale?: The selected language of the user invoking the interaction.
Expand All @@ -354,7 +351,6 @@ class CommandContext(_Context):
"channel_id",
"responded",
"deferred",
#
"locale",
"guild_locale",
)
Expand All @@ -380,13 +376,14 @@ def __init__(self, **kwargs) -> None:
async def edit(self, content: Optional[str] = MISSING, **kwargs) -> Message:

payload = await super().edit(content, **kwargs)
msg = None

if self.deferred:
if hasattr(self.message, "id") and self.message.id is not None:
res = await self.client.edit_message(
int(self.channel_id), int(self.message.id), payload=payload._json
)
self.message = Message(**res, _client=self.client)
self.message = msg = Message(**res, _client=self.client)
else:
res = await self.client.edit_interaction_response(
token=self.token,
Expand All @@ -402,7 +399,7 @@ async def edit(self, content: Optional[str] = MISSING, **kwargs) -> Message:
await self.client.edit_message(
int(self.channel_id), res["id"], payload=payload._json
)
self.message = Message(**res, _client=self.client)
self.message = msg = Message(**res, _client=self.client)
else:
res = await self.client.edit_interaction_response(
token=self.token,
Expand All @@ -415,8 +412,10 @@ async def edit(self, content: Optional[str] = MISSING, **kwargs) -> Message:
await self.client.edit_message(
int(self.channel_id), res["id"], payload=payload._json
)
self.message = Message(**res, _client=self.client)
self.message = msg = Message(**res, _client=self.client)

if msg is not None:
return msg
return payload

async def defer(self, ephemeral: Optional[bool] = False) -> None:
Expand Down Expand Up @@ -454,7 +453,7 @@ async def send(self, content: Optional[str] = MISSING, **kwargs) -> Message:
application_id=str(self.application_id),
)
self.responded = True
self.message = Message(**res, _client=self.client)
self.message = msg = Message(**res, _client=self.client)
else:
await self.client._post_followup(
data=payload._json,
Expand All @@ -477,8 +476,9 @@ async def send(self, content: Optional[str] = MISSING, **kwargs) -> Message:
msg = Message(**__newdata, _client=self.client)
self.message = msg
self.responded = True

return msg or payload
if msg is not None:
return msg
return payload

async def delete(self) -> None:
"""
Expand Down Expand Up @@ -569,7 +569,6 @@ class ComponentContext(_Context):
"channel_id",
"responded",
"deferred",
#
"locale",
"guild_locale",
)
Expand All @@ -582,6 +581,7 @@ def __init__(self, **kwargs) -> None:
async def edit(self, content: Optional[str] = MISSING, **kwargs) -> Message:

payload = await super().edit(content, **kwargs)
msg = None

if not self.deferred:
self.callback = InteractionCallbackType.UPDATE_MESSAGE
Expand All @@ -605,7 +605,10 @@ async def edit(self, content: Optional[str] = MISSING, **kwargs) -> Message:
application_id=str(self.application_id),
)
self.responded = True
self.message = Message(**res, _client=self.client)
self.message = msg = Message(**res, _client=self.client)

if msg is not None:
return msg

return payload

Expand All @@ -630,7 +633,7 @@ async def send(self, content: Optional[str] = MISSING, **kwargs) -> Message:
application_id=str(self.application_id),
)
self.responded = True
self.message = Message(**res, _client=self.client)
self.message = msg = Message(**res, _client=self.client)
else:
await self.client._post_followup(
data=payload._json,
Expand All @@ -654,7 +657,9 @@ async def send(self, content: Optional[str] = MISSING, **kwargs) -> Message:
self.message = msg
self.responded = True

return msg or payload
if msg is not None:
return msg
return payload

async def defer(
self, ephemeral: Optional[bool] = False, edit_origin: Optional[bool] = False
Expand Down