






















@@ -117,6 +117,12 @@ function createDmClient(channelId: string): DiscordClient {
117117} as unknown as DiscordClient;
118118}
119119120+function createMissingChannelClient(): DiscordClient {
121+return {
122+fetchChannel: async () => null,
123+} as unknown as DiscordClient;
124+}
125+120126async function runThreadBoundPreflight(params: {
121127threadId: string;
122128parentId: string;
@@ -203,6 +209,26 @@ async function runDmPreflight(params: {
203209});
204210}
205211212+async function runUnresolvedDmPreflight(params: {
213+cfg?: import("openclaw/plugin-sdk/config-types").OpenClawConfig;
214+channelId: string;
215+message: import("../internal/discord.js").Message;
216+discordConfig: DiscordConfig;
217+}) {
218+return preflightDiscordMessage({
219+ ...createPreflightArgs({
220+cfg: params.cfg ?? DEFAULT_PREFLIGHT_CFG,
221+discordConfig: params.discordConfig,
222+data: {
223+channel_id: params.channelId,
224+author: params.message.author,
225+message: params.message,
226+} as DiscordMessageEvent,
227+client: createMissingChannelClient(),
228+}),
229+});
230+}
231+206232async function runMentionOnlyBotPreflight(params: {
207233channelId: string;
208234guildId: string;
@@ -483,6 +509,38 @@ describe("preflightDiscordMessage", () => {
483509expect(result?.preflightAudioTranscript).toBe("hello openclaw from dm audio");
484510});
485511512+it("keeps no-guild messages direct when channel lookup is unavailable", async () => {
513+const result = await runUnresolvedDmPreflight({
514+cfg: {
515+ ...DEFAULT_PREFLIGHT_CFG,
516+session: {
517+ ...DEFAULT_PREFLIGHT_CFG.session,
518+dmScope: "per-channel-peer",
519+},
520+},
521+channelId: "dm-channel-unresolved-1",
522+message: createDiscordMessage({
523+id: "m-dm-unresolved-1",
524+channelId: "dm-channel-unresolved-1",
525+content: "hello from a degraded dm",
526+author: {
527+id: "user-1",
528+bot: false,
529+username: "alice",
530+},
531+}),
532+discordConfig: {
533+dmPolicy: "open",
534+} as DiscordConfig,
535+});
536+537+expect(result).not.toBeNull();
538+expect(result?.channelInfo).toBeNull();
539+expect(result?.isDirectMessage).toBe(true);
540+expect(result?.isGroupDm).toBe(false);
541+expect(result?.route.sessionKey).toBe("agent:main:discord:direct:user-1");
542+});
543+486544it("falls back to the default discord account for omitted-account dm authorization", async () => {
487545const message = createDiscordMessage({
488546id: "m-dm-default-account",
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。