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

Discord.js v14创建频道报错Invalid Form Body的排查求助

问题原因分析与解决方案

核心错误原因

  1. Discord.js v14频道创建API参数变更

    • v14版本中,GuildChannelManager.create()不再支持将频道名称作为第一个独立参数,所有配置项必须统一放在options对象内。你的代码中把name放在了第一个参数位置,导致API请求的name字段为undefined,触发name[BASE_TYPE_REQUIRED]错误。
    • 频道类型不能使用字符串"text",必须使用ChannelType枚举值(如ChannelType.GuildText),否则请求的type字段也会是undefined。
  2. Intents配置错误

    • 代码中Object.keys(discord.IntentsBitField.Flags)获取的是intents的键名(如"Guilds"),而非对应的数值,会导致intents无法正确注册。虽然这不是当前频道创建错误的直接原因,但会引发后续功能异常。

解决方案

1. 修复频道创建代码

首先导入ChannelType枚举:

const { ChannelType } = require('discord.js');

然后修改频道创建的逻辑,将name和type移入options对象:

// create the private channel
message.guild.channels
  .create({
    name: `order-${orderNumber}`, // 将名称移入options
    type: ChannelType.GuildText, // 使用v14的频道类型枚举
    permissionOverwrites: [
      {
        id: message.guild.roles.everyone,
        deny: ["VIEW_CHANNEL"],
      },
      {
        id: message.author.id,
        allow: ["VIEW_CHANNEL"],
      },
    ],
  })
  .catch(async (err) => {
    await logger.error(err);
    await console.log(err);

    await message.channel.send({
      embeds: [embeds.error("DC-4API-OR")],
    });
  })
  .then(async (channel) => {
    await channel.send({
      embeds: [
        embeds.embed(
          "Customize your order",
          "You may customize your order or simply enter the ID to one of our pre-made items."
        ),
      ],
    });
    await message.channel.send({
      embeds: [
        embeds.embed(
          "You have opened up a new order with us!",
          "Head over to the channel and tell us what you would like, and we will get to you ASAP."
        ),
      ],
    });
  });

同时确认orderNumber变量已正确赋值,确保order-${orderNumber}是有效的字符串(非undefined/null)。

2. 修复Intents配置

移除无效的Object.keys(discord.IntentsBitField.Flags),保留实际需要的intents数值:

// create a client object
const client = new discord.Client({
  // declare our gateway intents
  partials: ["MESSAGE", "CHANNEL", "REACTION"],
  intents: [
    discord.IntentsBitField.Flags.Guilds, // 服务器操作必备
    discord.IntentsBitField.Flags.GuildMessages, // 处理服务器消息
    discord.IntentsBitField.Flags.MessageContent, // 读取消息内容(需在Discord开发者门户开启)
    discord.IntentsBitField.Flags.GuildWebhooks,
    discord.IntentsBitField.Flags.GuildIntegrations,
    discord.IntentsBitField.Flags.GuildMessageTyping,
  ],
});

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.20 10:57:35