Skip to content

The agent that grows with you

refactor: the Discord approval card retires through the views' shared embed stamp

kshitijk4poor1d90557426dc
diff --git a/plugins/platforms/discord/adapter.py b/plugins/platforms/discord/adapter.py
index 61a9e6255f6..509b4cc6cac 100644
--- a/plugins/platforms/discord/adapter.py
+++ b/plugins/platforms/discord/adapter.py
@@ -6413,8 +6413,9 @@ def _define_discord_view_classes() -> None:
def _first_embed(message):
return message.embeds[0] if message.embeds else None
- async def _expire_embed(self, footer: str) -> None:
- """Grey out the original message's embed after a timeout (best effort)."""
+ async def _expire_embed(self, footer: str, *, keep_controls: bool = True) -> None:
+ """Grey out the original message's embed and stamp ``footer`` (best effort). The disabled
+ buttons stay unless ``keep_controls`` is False, which removes them."""
msg = self._message
if msg:
try:
@@ -6422,9 +6423,9 @@ def _define_discord_view_classes() -> None:
if embed:
embed.color = discord.Color.greyple()
embed.set_footer(text=footer)
- await msg.edit(embed=embed, view=self)
+ await msg.edit(embed=embed, view=self if keep_controls else None)
except Exception:
- pass # message deleted or too old to edit
+ logger.debug("[Discord] Could not stamp prompt card", exc_info=True) # deleted / too old
async def _finalize_embed(self, interaction: discord.Interaction, color, footer: str) -> None:
"""Mark resolved, stamp the embed (color + footer), disable buttons, edit in place, then
diff --git a/plugins/platforms/discord/adapter_exec_approval_view.py b/plugins/platforms/discord/adapter_exec_approval_view.py
index 4c4ae829653..a7998661d1b 100644
--- a/plugins/platforms/discord/adapter_exec_approval_view.py
+++ b/plugins/platforms/discord/adapter_exec_approval_view.py
@@ -85,16 +85,8 @@ def build_exec_approval_view(discord, base, *, unauthorized):
"timeout": "platform.discord.prompt.expired_footer",
"gone": "platform.discord.approval.no_longer_pending",
}.get(reason, "platform.discord.slash_confirm.resolved_cancel"))
- if self._message:
- try:
- embed = self._first_embed(self._message)
- if embed:
- embed.color = discord.Color.greyple()
- embed.set_footer(text=footer)
- # Notices edit content independently; neither restores controls.
- await self._message.edit(embed=embed, view=None)
- except Exception:
- logger.debug("[Discord] Could not retire approval card", exc_info=True)
+ # The timeout notice edits only the content, so it never restores the controls.
+ await self._expire_embed(footer, keep_controls=False)
async def _resolve(self, interaction: discord.Interaction, choice: str, color: discord.Color, label_key: str):
"""Resolve the approval via the gateway approval queue and update the embed."""