@@ -10,7 +10,6 @@ import { resolveChunkMode, type ChunkMode } from "openclaw/plugin-sdk/reply-chun
1010import type { RetryConfig } from "openclaw/plugin-sdk/retry-runtime" ;
1111import { normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime" ;
1212import { truncateUtf16Safe } from "openclaw/plugin-sdk/text-utility-runtime" ;
13- import { resolveDiscordAccount } from "./accounts.js" ;
1413import { createChannelMessage , createThread , type RequestClient } from "./internal/discord.js" ;
1514import { renderDiscordMarkdown } from "./markdown.js" ;
1615import { rewriteDiscordKnownMentions } from "./mentions.js" ;
@@ -159,12 +158,17 @@ function toDiscordSendResult(
159158async function resolveDiscordSendTarget (
160159 to : string ,
161160 opts : DiscordSendOpts ,
162- ) : Promise < { rest : RequestClient ; request : DiscordClientRequest ; channelId : string } > {
161+ ) : Promise < {
162+ rest : RequestClient ;
163+ request : DiscordClientRequest ;
164+ channelId : string ;
165+ account : ReturnType < typeof createDiscordClient > [ "account" ] ;
166+ } > {
163167 const cfg = requireRuntimeConfig ( opts . cfg , "Discord send target resolution" ) ;
164- const { rest, request } = createDiscordClient ( { ...opts , cfg } ) ;
165- const recipient = await parseAndResolveChannelRecipient ( to , cfg , opts . accountId ) ;
168+ const { rest, request, account } = createDiscordClient ( { ...opts , cfg } ) ;
169+ const recipient = await parseAndResolveChannelRecipient ( to , cfg , account . accountId ) ;
166170 const { channelId } = await resolveChannelId ( rest , recipient , request ) ;
167- return { rest, request, channelId } ;
171+ return { rest, request, channelId, account } ;
168172}
169173
170174export async function sendMessageDiscord (
@@ -173,10 +177,7 @@ export async function sendMessageDiscord(
173177 opts : DiscordSendOpts ,
174178) : Promise < DiscordSendResult > {
175179 const cfg = requireRuntimeConfig ( opts . cfg , "Discord send" ) ;
176- const accountInfo = resolveDiscordAccount ( {
177- cfg,
178- accountId : opts . accountId ,
179- } ) ;
180+ const { token, rest, request, account : accountInfo } = createDiscordClient ( { ...opts , cfg } ) ;
180181 const tableMode = resolveMarkdownTableMode ( {
181182 cfg,
182183 channel : "discord" ,
@@ -202,8 +203,7 @@ export async function sendMessageDiscord(
202203 accountId : accountInfo . accountId ,
203204 mentionAliases : accountInfo . config . mentionAliases ,
204205 } ) ;
205- const { token, rest, request } = createDiscordClient ( { ...opts , cfg } ) ;
206- const recipient = await parseAndResolveChannelRecipient ( to , cfg , opts . accountId ) ;
206+ const recipient = await parseAndResolveChannelRecipient ( to , cfg , accountInfo . accountId ) ;
207207 const { channelId } = await resolveChannelId ( rest , recipient , request ) ;
208208
209209 // Forum/Media channels reject POST /messages; auto-create a thread post instead.
@@ -490,12 +490,13 @@ async function resolveDiscordStructuredSendContext(
490490 rewrittenContent ?: string ;
491491 suppressEmbeds : boolean ;
492492} > {
493- const cfg = requireRuntimeConfig ( opts . cfg , "Discord structured send" ) ;
494- const accountInfo = resolveDiscordAccount ( {
495- cfg,
496- accountId : opts . accountId ,
497- } ) ;
498- const { rest, request, channelId } = await resolveDiscordSendTarget ( to , opts ) ;
493+ requireRuntimeConfig ( opts . cfg , "Discord structured send" ) ;
494+ const {
495+ rest,
496+ request,
497+ channelId,
498+ account : accountInfo ,
499+ } = await resolveDiscordSendTarget ( to , opts ) ;
499500 const content = opts . content ?. trim ( ) ;
500501 const rewrittenContent = content
501502 ? rewriteDiscordKnownMentions ( content , {
0 commit comments