discordapierror [50035]:无效的表单正文0.名称[base_type_required]:此字段是必需的1.名称[base_type_required]:需要此字段

发布于 2025-02-11 07:29:37 字数 1960 浏览 1 评论 0原文

在创建slash命令构建器以供帮助命令时,它不会被注册并给出以下错误 -

DiscordAPIError[50035]: Invalid Form Body
    0.name[BASE_TYPE_REQUIRED]: This field is required
    1.name[BASE_TYPE_REQUIRED]: This field is required
        at SequentialHandler.runRequest (P:\Backend\helpdesk-bot\node_modules\@discordjs\rest\dist\index.js:753:15)
        at processTicksAndRejections (node:internal/process/task_queues:96:5)
        at async SequentialHandler.queueRequest (P:\Backend\helpdesk-bot\node_modules\@discordjs\rest\dist\index.js:565:14)
        at async REST.request (P:\Backend\helpdesk-bot\node_modules\@discordjs\rest\dist\index.js:999:22) {
      rawError: {
code: 50035,
    errors: { '0': [Object], '1': [Object] },
    message: 'Invalid Form Body'
  },
  code: 50035,
  status: 400,
  method: 'PUT',
  url: 'https://discord.com/api/v10/applications/client_id/guilds/guild_id/commands',
  requestBody: { files: undefined, json: [ [Object], [Object] ] }
}

我在其他文件中创建一个help命令,并通过index.ts文件导出它 help.ts

export const data = new SlashCommandBuilder()
.setName('help')
.setDescription('creates a new help ticket')
.addStringOption((option) =>
option
.setName('description')
.setDescription('describe your query')
.setRequired(true)
   );
export async function execute(interaction: CommandInteraction, client: Client) {
return interaction.reply('pong');
}

部署命令基本上从命令文件夹中获取每个文件,并将其添加到命令数组中。现在,在制作基本的ping pong命令时,命令在运行deploy-commands.ts之后会注册,但是在添加帮助命令后,它给出了上述错误 deploy-commands.ts

type Command = {
data: unknown;
};

const commands = [];

for (const module of Object.values<Command>(commandModules)) {
commands.push(module);
}

const rest = new REST({ version: '10' }).setToken(config.DISCORD_TOKEN);

rest
.put(Routes.applicationGuildCommands(config.CLIENT_ID, config.GUILD_ID), {
body: commands,
}).then(() => {
console.log('registered application commands');
})
.catch(console.error);

while creating a slash command builder for a help command, it does not gets registered and gives the following error -

DiscordAPIError[50035]: Invalid Form Body
    0.name[BASE_TYPE_REQUIRED]: This field is required
    1.name[BASE_TYPE_REQUIRED]: This field is required
        at SequentialHandler.runRequest (P:\Backend\helpdesk-bot\node_modules\@discordjs\rest\dist\index.js:753:15)
        at processTicksAndRejections (node:internal/process/task_queues:96:5)
        at async SequentialHandler.queueRequest (P:\Backend\helpdesk-bot\node_modules\@discordjs\rest\dist\index.js:565:14)
        at async REST.request (P:\Backend\helpdesk-bot\node_modules\@discordjs\rest\dist\index.js:999:22) {
      rawError: {
code: 50035,
    errors: { '0': [Object], '1': [Object] },
    message: 'Invalid Form Body'
  },
  code: 50035,
  status: 400,
  method: 'PUT',
  url: 'https://discord.com/api/v10/applications/client_id/guilds/guild_id/commands',
  requestBody: { files: undefined, json: [ [Object], [Object] ] }
}

i am creating a help command in a different file and exporting it via index.ts file
help.ts

export const data = new SlashCommandBuilder()
.setName('help')
.setDescription('creates a new help ticket')
.addStringOption((option) =>
option
.setName('description')
.setDescription('describe your query')
.setRequired(true)
   );
export async function execute(interaction: CommandInteraction, client: Client) {
return interaction.reply('pong');
}

deploy command basically takes each file from command folders and adds it into the commands array. Now while making a basic ping pong command the commands get registered after running deploy-commands.ts, but after adding the help command it gives the above error
deploy-commands.ts

type Command = {
data: unknown;
};

const commands = [];

for (const module of Object.values<Command>(commandModules)) {
commands.push(module);
}

const rest = new REST({ version: '10' }).setToken(config.DISCORD_TOKEN);

rest
.put(Routes.applicationGuildCommands(config.CLIENT_ID, config.GUILD_ID), {
body: commands,
}).then(() => {
console.log('registered application commands');
})
.catch(console.error);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文