























@@ -1,3 +1,4 @@
1+import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
12import {
23assertMediaNotDataUrl,
34jsonResult,
@@ -8,6 +9,7 @@ import {
89resolvePollMaxSelections,
910} from "../runtime-api.js";
1011import { DiscordThreadInitialMessageError } from "../send.js";
12+import { isThreadChannelType } from "../send.permissions.js";
1113import type { DiscordSendComponents, DiscordSendEmbeds } from "../send.shared.js";
1214import { discordMessagingActionRuntime } from "./runtime.messaging.runtime.js";
1315import type { DiscordMessagingActionContext } from "./runtime.messaging.shared.js";
@@ -21,6 +23,69 @@ function hasDiscordComponentObjectKeys(value: unknown): value is Record<string,
2123);
2224}
232526+async function appendDiscordThreadRenameResult(
27+ctx: DiscordMessagingActionContext,
28+params: {
29+payload: Record<string, unknown>;
30+target: string;
31+threadName?: string;
32+},
33+) {
34+const threadName = params.threadName?.trim();
35+if (!threadName) {
36+return params.payload;
37+}
38+if (!ctx.isActionEnabled("channels")) {
39+return {
40+ ...params.payload,
41+warning: "Discord threadName was ignored because Discord channel management is disabled.",
42+};
43+}
44+45+let channelId: string;
46+try {
47+channelId = discordMessagingActionRuntime.resolveDiscordChannelId(params.target);
48+} catch {
49+return {
50+ ...params.payload,
51+warning: "Discord threadName was ignored because the send target is not a channel/thread.",
52+};
53+}
54+55+try {
56+const channel = await discordMessagingActionRuntime.fetchChannelInfoDiscord(
57+channelId,
58+ctx.withOpts(),
59+);
60+if (!isThreadChannelType(channel.type)) {
61+return {
62+ ...params.payload,
63+warning: "Discord threadName was ignored because the send target is not a thread.",
64+};
65+}
66+const renamed = await discordMessagingActionRuntime.editChannelDiscord(
67+{
68+ channelId,
69+name: threadName,
70+},
71+ctx.withOpts(),
72+);
73+return {
74+ ...params.payload,
75+threadRename: {
76+ok: true,
77+ channelId,
78+name: renamed.name ?? threadName,
79+},
80+};
81+} catch (error) {
82+return {
83+ ...params.payload,
84+warning: `Discord message was sent, but thread rename failed: ${formatErrorMessage(error)}`,
85+};
86+}
87+}
88+2489export async function handleDiscordMessageSendAction(ctx: DiscordMessagingActionContext) {
2590switch (ctx.action) {
2691case "sticker": {
@@ -88,6 +153,7 @@ export async function handleDiscordMessageSendAction(ctx: DiscordMessagingAction
88153});
89154const filename = readStringParam(ctx.params, "filename");
90155const replyTo = readStringParam(ctx.params, "replyTo");
156+const threadName = readStringParam(ctx.params, "threadName");
91157const rawEmbeds = ctx.params.embeds;
92158const embeds: DiscordSendEmbeds | undefined = Array.isArray(rawEmbeds)
93159 ? (rawEmbeds as DiscordSendEmbeds)
@@ -122,7 +188,13 @@ export async function handleDiscordMessageSendAction(ctx: DiscordMessagingAction
122188mediaReadFile: ctx.options?.mediaReadFile,
123189},
124190);
125-return jsonResult({ ok: true, result, components: true });
191+return jsonResult(
192+await appendDiscordThreadRenameResult(ctx, {
193+payload: { ok: true, result, components: true },
194+target: to,
195+ threadName,
196+}),
197+);
126198}
127199128200if (asVoice) {
@@ -142,7 +214,13 @@ export async function handleDiscordMessageSendAction(ctx: DiscordMessagingAction
142214 replyTo,
143215 silent,
144216});
145-return jsonResult({ ok: true, result, voiceMessage: true });
217+return jsonResult(
218+await appendDiscordThreadRenameResult(ctx, {
219+payload: { ok: true, result, voiceMessage: true },
220+target: to,
221+ threadName,
222+}),
223+);
146224}
147225148226const result = await discordMessagingActionRuntime.sendMessageDiscord(to, content ?? "", {
@@ -157,7 +235,13 @@ export async function handleDiscordMessageSendAction(ctx: DiscordMessagingAction
157235 embeds,
158236 silent,
159237});
160-return jsonResult({ ok: true, result });
238+return jsonResult(
239+await appendDiscordThreadRenameResult(ctx, {
240+payload: { ok: true, result },
241+target: to,
242+ threadName,
243+}),
244+);
161245}
162246case "threadCreate": {
163247if (!ctx.isActionEnabled("threads")) {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。