























@@ -1165,6 +1165,64 @@ describe("processDiscordMessage session routing", () => {
11651165expect(dispatchCtx.MediaPaths).toBeUndefined();
11661166});
116711671168+it("does not inject the bot's previous message body when users reply to it", async () => {
1169+const fetchImpl = vi.fn(async () => {
1170+throw new Error("self-reply media should not be fetched");
1171+});
1172+const ctx = await createBaseContext({
1173+botUserId: "bot-1",
1174+cfg: {
1175+channels: { discord: { contextVisibility: "all" } },
1176+messages: { ackReaction: "👀" },
1177+session: { store: "/tmp/openclaw-discord-process-test-sessions.json" },
1178+},
1179+discordRestFetch: fetchImpl,
1180+message: {
1181+id: "m-self-reply",
1182+channelId: "c1",
1183+content: "<@bot> hit that again",
1184+timestamp: new Date().toISOString(),
1185+attachments: [],
1186+messageReference: {
1187+type: 0,
1188+message_id: "m-bot-previous",
1189+channel_id: "c1",
1190+},
1191+referencedMessage: {
1192+id: "m-bot-previous",
1193+channelId: "c1",
1194+content: "The same stale bot response keeps looping.",
1195+timestamp: new Date().toISOString(),
1196+attachments: [
1197+{
1198+id: "att-bot-previous",
1199+url: "https://cdn.discordapp.com/attachments/previous.png",
1200+content_type: "image/png",
1201+filename: "previous.png",
1202+},
1203+],
1204+author: {
1205+id: "bot-1",
1206+username: "Spartacus",
1207+discriminator: "0",
1208+globalName: "Spartacus",
1209+},
1210+},
1211+},
1212+baseText: "<@bot> hit that again",
1213+messageText: "<@bot> hit that again",
1214+});
1215+1216+await runProcessDiscordMessage(ctx);
1217+1218+const dispatchCtx = requireRecord(getLastDispatchCtx(), "dispatch context");
1219+expect(fetchImpl).not.toHaveBeenCalled();
1220+expect(dispatchCtx.ReplyToId).toBe("m-bot-previous");
1221+expect(dispatchCtx.ReplyToSender).toBe("Spartacus");
1222+expect(dispatchCtx.ReplyToBody).toBeUndefined();
1223+expect(JSON.stringify(dispatchCtx)).not.toContain("The same stale bot response keeps looping.");
1224+});
1225+11681226it("stores DM lastRoute with user target for direct-session continuity", async () => {
11691227const ctx = await createBaseContext({
11701228 ...createDirectMessageContextOverrides(),
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。