You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

DiscordAPIError[50035]报错解决:guild_id为undefined问题处理

解决DiscordAPIError[50035]: Invalid Form Body报错

问题现象

开发Discord机器人时触发DiscordAPIError[50035]: Invalid Form Body错误,核心提示为guild_id[NUMBER_TYPE_COERCE]: Value "undefined" is not snowflake,完整报错信息如下:

DiscordAPIError[50035]: Invalid Form Body
    guild_id[NUMBER_TYPE_COERCE]: Value "undefined" is not snowflake.
        at processTicksAndRejections (node:internal/process/task_queues:96:5)
        at async SequentialHandler.queueRequest (C:\discord\TIP-BOT\node_modules\@discordjs\rest\dist\lib\handlers\SequentialHandler.cjs:99:14)
        at async REST.request (C:\discord\TIP-BOT\node_modules\@discordjs\rest\dist\lib\REST.cjs:52:22)
        at async Client.<anonymous> (C:\discord\TIP-BOT\bot.js:51:7) {
      rawError: {
        code: 50035,
        errors: { guild_id: [Object] },
        message: 'Invalid Form Body'
      },
      code: 50035,
      status: 400,
      method: 'PUT',
      url: 'https://discord.com/api/v9/applications/999345819608158280/guilds/undefined/commands',
      requestBody: { files: undefined, json: [ [Object] ] }

解决方案

将clientId和guildId预先定义为变量,再传入Routes.applicationGuildCommands方法,而非直接传入ID字符串值。示例代码如下:

const clientId = '你的机器人客户端ID';
const guildId = '你的服务器ID';    

try {
    await rest.put(
        Routes.applicationGuildCommands(clientId, guildId),
        { body: commands },
    ); 
} catch (error) {
    console.log(error);
}

核心原因

直接传入ID值时可能出现解析异常,导致guild_id被识别为undefined,不符合Discord API要求的雪花ID格式。通过变量预先存储ID值,可确保参数正确传递至API请求中。

内容的提问来源于stack exchange,提问作者ah ab

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 12:46:57