diff --git a/extensions/discord/src/send.outbound.ts b/extensions/discord/src/send.outbound.ts index ca13d9a5b64..57676d98d67 100644 --- a/extensions/discord/src/send.outbound.ts +++ b/extensions/discord/src/send.outbound.ts @@ -432,18 +432,10 @@ export async function sendStickerDiscord( stickerIds: string[], opts: DiscordSendOpts & { content?: string } = {}, ): Promise { - const cfg = opts.cfg ?? loadConfig(); - const accountInfo = resolveDiscordAccount({ - cfg, - accountId: opts.accountId, - }); - const { rest, request, channelId } = await resolveDiscordSendTarget(to, opts); - const content = opts.content?.trim(); - const rewrittenContent = content - ? rewriteDiscordKnownMentions(content, { - accountId: accountInfo.accountId, - }) - : undefined; + const { rest, request, channelId, rewrittenContent } = await resolveDiscordStructuredSendContext( + to, + opts, + ); const stickers = normalizeStickerIds(stickerIds); const res = (await request( () => @@ -463,18 +455,10 @@ export async function sendPollDiscord( poll: PollInput, opts: DiscordSendOpts & { content?: string } = {}, ): Promise { - const cfg = opts.cfg ?? loadConfig(); - const accountInfo = resolveDiscordAccount({ - cfg, - accountId: opts.accountId, - }); - const { rest, request, channelId } = await resolveDiscordSendTarget(to, opts); - const content = opts.content?.trim(); - const rewrittenContent = content - ? rewriteDiscordKnownMentions(content, { - accountId: accountInfo.accountId, - }) - : undefined; + const { rest, request, channelId, rewrittenContent } = await resolveDiscordStructuredSendContext( + to, + opts, + ); if (poll.durationSeconds !== undefined) { throw new Error("Discord polls do not support durationSeconds; use durationHours"); } @@ -494,6 +478,30 @@ export async function sendPollDiscord( return toDiscordSendResult(res, channelId); } +async function resolveDiscordStructuredSendContext( + to: string, + opts: DiscordSendOpts & { content?: string }, +): Promise<{ + rest: RequestClient; + request: DiscordClientRequest; + channelId: string; + rewrittenContent?: string; +}> { + const cfg = opts.cfg ?? loadConfig(); + const accountInfo = resolveDiscordAccount({ + cfg, + accountId: opts.accountId, + }); + const { rest, request, channelId } = await resolveDiscordSendTarget(to, opts); + const content = opts.content?.trim(); + const rewrittenContent = content + ? rewriteDiscordKnownMentions(content, { + accountId: accountInfo.accountId, + }) + : undefined; + return { rest, request, channelId, rewrittenContent }; +} + type VoiceMessageOpts = { cfg?: OpenClawConfig; token?: string;