

















@@ -219,21 +219,35 @@ export async function fetchDiscordBotIdentity(params: {
219219logStartupPhase: (phase: string, details?: string) => void;
220220}) {
221221params.logStartupPhase("fetch-bot-identity:start");
222+let botUser: Awaited<ReturnType<typeof params.client.fetchUser>>;
222223try {
223-const botUser = await params.client.fetchUser("@me");
224-const botUserId = botUser?.id;
225-const botUserName =
226-normalizeOptionalString(botUser?.username) ?? normalizeOptionalString(botUser?.globalName);
227-params.logStartupPhase(
228-"fetch-bot-identity:done",
229-`botUserId=${botUserId ?? "<missing>"} botUserName=${botUserName ?? "<missing>"}`,
230-);
231-return { botUserId, botUserName };
224+botUser = await params.client.fetchUser("@me");
232225} catch (err) {
233226params.runtime.error?.(danger(`discord: failed to fetch bot identity: ${String(err)}`));
234227params.logStartupPhase("fetch-bot-identity:error", String(err));
235-return { botUserId: undefined, botUserName: undefined };
228+throw new Error("Failed to resolve Discord bot identity", { cause: err });
229+}
230+231+const botUserRecord = botUser as
232+| { id?: unknown; username?: unknown; globalName?: unknown }
233+| null
234+| undefined;
235+const botUserId = normalizeOptionalString(botUserRecord?.id);
236+const botUserName =
237+normalizeOptionalString(botUserRecord?.username) ??
238+normalizeOptionalString(botUserRecord?.globalName);
239+if (!botUserId) {
240+const details = 'fetchUser("@me") returned no usable id';
241+params.runtime.error?.(danger(`discord: failed to fetch bot identity: ${details}`));
242+params.logStartupPhase("fetch-bot-identity:error", details);
243+throw new Error("Failed to resolve Discord bot identity");
236244}
245+246+params.logStartupPhase(
247+"fetch-bot-identity:done",
248+`botUserId=${botUserId} botUserName=${botUserName ?? "<missing>"}`,
249+);
250+return { botUserId, botUserName };
237251}
238252239253export function registerDiscordMonitorListeners(params: {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。