Discord: resolve bind approvals in-place

This commit is contained in:
huntharo 2026-03-20 18:53:55 -04:00
parent 1a188ffb87
commit b334cf63f5
No known key found for this signature in database
2 changed files with 20 additions and 19 deletions

View File

@ -168,10 +168,11 @@ async function dispatchPluginDiscordInteractiveEvent(params: {
decision: pluginBindingApproval.decision,
senderId: params.interactionCtx.userId,
});
let cleared = false;
try {
await respond.clearComponents();
cleared = true;
await respond.clearComponents({
text: buildPluginBindingResolvedText(resolved),
});
return "handled";
} catch {
try {
await respond.acknowledge();
@ -180,21 +181,19 @@ async function dispatchPluginDiscordInteractiveEvent(params: {
}
}
try {
await respond.followUp({
await respond.reply({
text: buildPluginBindingResolvedText(resolved),
ephemeral: true,
});
} catch (err) {
logError(`discord plugin binding approval: failed to follow up: ${String(err)}`);
if (!cleared) {
try {
await respond.reply({
text: buildPluginBindingResolvedText(resolved),
ephemeral: true,
});
} catch {
// Interaction may no longer accept a direct reply.
}
logError(`discord plugin binding approval: failed to reply: ${String(err)}`);
try {
await respond.followUp({
text: buildPluginBindingResolvedText(resolved),
ephemeral: true,
});
} catch {
// Interaction may no longer accept a follow-up.
}
}
return "handled";

View File

@ -918,11 +918,13 @@ describe("discord component interactions", () => {
await button.run(interaction, { cid: "btn_1" } as ComponentData);
expect(update).toHaveBeenCalledWith({ components: [] });
expect(followUp).toHaveBeenCalledWith({
content: expect.stringContaining("bind approval"),
ephemeral: true,
});
expect(update).toHaveBeenCalledWith(
expect.objectContaining({
content: expect.any(String),
components: [],
}),
);
expect(followUp).not.toHaveBeenCalled();
expect(dispatchReplyMock).not.toHaveBeenCalled();
});
});