





























@@ -2,8 +2,10 @@ import { formatDurationSeconds, warn, type RuntimeEnv } from "openclaw/plugin-sd
22import { formatErrorMessage } from "openclaw/plugin-sdk/ssrf-runtime";
33import { Client, overwriteApplicationCommands, type RequestClient } from "../internal/discord.js";
44import {
5+attachDiscordDeployRestContext,
56attachDiscordDeployRequestBody,
67formatDiscordDeployErrorDetails,
8+formatDiscordDeployErrorMessage,
79formatDiscordDeployRateLimitDetails,
810formatDiscordDeployRateLimitWarning,
911isDiscordDeployDailyCreateLimit,
@@ -27,6 +29,7 @@ function wrapDeployRestMethod(params: {
2729runtime: RuntimeEnv;
2830accountId: string;
2931startupStartedAt: number;
32+timeoutMs?: number;
3033shouldLogVerbose: () => boolean;
3134}) {
3235return async (path: string, data?: never, query?: never) => {
@@ -51,20 +54,27 @@ function wrapDeployRestMethod(params: {
5154}
5255return result;
5356} catch (err) {
57+const requestMs = Date.now() - startedAt;
5458attachDiscordDeployRequestBody(err, body);
59+attachDiscordDeployRestContext(err, {
60+method: params.method,
61+ path,
62+ requestMs,
63+timeoutMs: params.timeoutMs,
64+});
5565const rateLimitDetails = formatDiscordDeployRateLimitDetails(err);
5666if (rateLimitDetails) {
5767if (params.shouldLogVerbose()) {
5868params.runtime.log?.(
5969warn(
60-`discord startup [${params.accountId}] native-slash-command-deploy-rest:${params.method}:rate-limited ${Math.max(0, Date.now() - params.startupStartedAt)}ms path=${path} requestMs=${Date.now() - startedAt}${rateLimitDetails}`,
70+`discord startup [${params.accountId}] native-slash-command-deploy-rest:${params.method}:rate-limited ${Math.max(0, Date.now() - params.startupStartedAt)}ms path=${path} requestMs=${requestMs}${rateLimitDetails}`,
6171),
6272);
6373}
6474} else {
6575const details = formatDiscordDeployErrorDetails(err);
6676params.runtime.error?.(
67-`discord startup [${params.accountId}] native-slash-command-deploy-rest:${params.method}:error ${Math.max(0, Date.now() - params.startupStartedAt)}ms path=${path} requestMs=${Date.now() - startedAt} error=${formatErrorMessage(err)}${details}`,
77+`discord startup [${params.accountId}] native-slash-command-deploy-rest:${params.method}:error ${Math.max(0, Date.now() - params.startupStartedAt)}ms path=${path} requestMs=${requestMs} error=${formatDiscordDeployErrorMessage(err)}${details}`,
6878);
6979}
7080throw err;
@@ -87,12 +97,14 @@ function installDeployRestLogging(params: {
8797delete: params.rest.delete.bind(params.rest),
8898};
8999for (const method of Object.keys(original) as RestMethodName[]) {
100+const timeout = (params.rest as { options?: { timeout?: unknown } }).options?.timeout;
90101params.rest[method] = wrapDeployRestMethod({
91102 method,
92103 original,
93104runtime: params.runtime,
94105accountId: params.accountId,
95106startupStartedAt: params.startupStartedAt,
107+timeoutMs: typeof timeout === "number" ? timeout : undefined,
96108shouldLogVerbose: params.shouldLogVerbose,
97109}) as RequestClient[typeof method];
98110}
@@ -168,7 +180,7 @@ export async function deployDiscordCommands(params: {
168180params.runtime.log?.(
169181warn(
170182rateLimitWarning ??
171-`discord: native slash command deploy warning (not message send): ${formatErrorMessage(err)}${formatDiscordDeployErrorDetails(err)}`,
183+`discord: native slash command deploy warning (not message send): ${formatDiscordDeployErrorMessage(err)}${formatDiscordDeployErrorDetails(err)}`,
172184),
173185);
174186} finally {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。