首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >当我运行我的不和谐机器人时,为什么会出现这个错误?-代码: 50035

当我运行我的不和谐机器人时,为什么会出现这个错误?-代码: 50035
EN

Stack Overflow用户
提问于 2022-09-15 08:35:21
回答 1查看 173关注 0票数 -1

当我运行通过Discord.js和Node.js框架创建的不和谐的机器人时,我会收到以下错误。

代码语言:javascript
运行
复制
node_modules\@discordjs\rest\dist\lib\handlers\SequentialHandler.cjs:293
        throw new DiscordAPIError.DiscordAPIError(data, "code" in data ? data.code : data.error, status, method, url, requestData);
              ^

DiscordAPIError[50035]: Invalid Form Body
options[0].type[NUMBER_TYPE_COERCE]: Value "string" is not int.
options[1].type[NUMBER_TYPE_COERCE]: Value "string" is not int.
    at SequentialHandler.runRequest (D:\Programming\GitHub\void-bot\node_modules\@discordjs\rest\dist\lib\handlers\SequentialHandler.cjs:293:15)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async SequentialHandler.queueRequest (D:\Programming\GitHub\void-bot\node_modules\@discordjs\rest\dist\lib\handlers\SequentialHandler.cjs:99:14)
    at async REST.request (D:\Programming\GitHub\void-bot\node_modules\@discordjs\rest\dist\lib\REST.cjs:52:22)
    at async GuildApplicationCommandManager.create (D:\Programming\GitHub\void-bot\node_modules\discord.js\src\managers\ApplicationCommandManager.js:144:18) {
  rawError: {
    code: 50035,
    errors: {
      options: {
        '0': { type: { _errors: [Array] } },
        '1': { type: { _errors: [Array] } }
      }
    },
    message: 'Invalid Form Body'
  },
  code: 50035,
  status: 400,
  method: 'POST',
  url: 'https://discord.com/api/v10/applications/1016623217399570512/guilds/915541815225118740/commands',
  requestBody: {
    files: undefined,
    json: {
      name: 'poll',
      name_localizations: undefined,
      description: 'Sets up a poll.',
      description_localizations: undefined,
      type: undefined,
      options: [
        {
          type: 'string',
          name: 'title',
          name_localizations: undefined,
          name_localized: undefined,
          description: 'The title of the poll.',
          description_localizations: undefined,
          description_localized: undefined,
          required: true,
          autocomplete: undefined,
          choices: undefined,
          options: undefined,
          channel_types: undefined,
          min_value: undefined,
          max_value: undefined,
          min_length: undefined,
          max_length: undefined
        },
        {
          type: 'string',
          name: 'content',
          name_localizations: undefined,
          name_localized: undefined,
          description: 'The content of the poll.',
          description_localizations: undefined,
          description_localized: undefined,
          required: true,
          autocomplete: undefined,
          choices: undefined,
          options: undefined,
          channel_types: undefined,
          min_value: undefined,
          max_value: undefined,
          min_length: undefined,
          max_length: undefined
        }
      ],
      default_member_permissions: undefined,
      dm_permission: undefined
    }
  }
}

我不知道为什么会收到下面的代码:

代码语言:javascript
运行
复制
require("dotenv").config();
const { GatewayIntentBits } = require("discord.js");
const Discord = require("discord.js");

const PREFIX = "!";

const client = new Discord.Client({
    intents: [
        GatewayIntentBits.Guilds,
        GatewayIntentBits.GuildMembers,
        GatewayIntentBits.GuildBans,
        GatewayIntentBits.GuildEmojisAndStickers,
        GatewayIntentBits.GuildIntegrations,
        GatewayIntentBits.GuildWebhooks,
        GatewayIntentBits.GuildInvites,
        GatewayIntentBits.GuildVoiceStates,
        GatewayIntentBits.GuildPresences,
        GatewayIntentBits.GuildMessages,
        GatewayIntentBits.GuildMessageReactions,
        GatewayIntentBits.GuildMessageTyping,
        GatewayIntentBits.DirectMessages,
        GatewayIntentBits.DirectMessageReactions,
        GatewayIntentBits.DirectMessageTyping,
        GatewayIntentBits.MessageContent,
        GatewayIntentBits.GuildScheduledEvents
    ]
});

client.on("ready", () => {
    console.log(`Logged in as ${client.user.tag}!`);

    const guildID = "915541815225118740";
    const guild = client.guilds.cache.get(guildID);
    let commands;

    if (guild) {
        commands = guild.commands;
    } else {
        commands = client.application?.commands;
    }

    commands?.create({
        name: "poll",
        description: "Sets up a poll.",
        options: [
            {
                name: "title",
                description: "The title of the poll.",
                required: true,
                type: "string"
            },
            {
                name: "content",
                description: "The content of the poll.",
                required: true,
                type: "string"
            }
        ]
    });
});

client.on("interactionCreate", async (interaction) => {
    if (!interaction.isCommand()) {
        return;
    }

    const { commandName, options } = interaction;

    if (commandName === "poll") {
        const embed = new Discord.EmbedBuilder()
            .setColor(0x0099FF)
            .setTitle(options.get("title"))
            .addFields(
                {
                    value: options.get("content"),
                    inline: false
                },
                {
                    value: ":thumbsup: - Yes",
                    inline: true
                },
                {
                    value: ":thumbsdown: - No",
                    inline: true
                }
            )
        }


        interaction.reply(embed);
});

client.login(process.env.TOKEN);

我希望有人能帮我解决这个问题。非常感谢,因为我在这个问题上已经坚持了几天了。

谢谢你,晕人

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-09-15 09:37:09

您已经使用字符串文本指定了选项类型。它应该是ApplicationCommandOptionType枚举的值。因此,您应该使用:

代码语言:javascript
运行
复制
{
  name: "...",
  description: "...",
  required: ...
  type: ApplicationCommandOptionType.STRING
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73727991

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档