我对discord.js v14还是个新手.我过go 使用V13,但现在V14有一个问题,我不能处理.

这是我的代码:

const { SlashCommandBuilder, EmbedBuilder , ButtonBuilder , ActionRowBuilder , SelectMenuBuilder} = require('discord.js');

module.exports = {
  data: new SlashCommandBuilder()
    .setName('bus-test')
    .setDescription('Just testing')
    .addAttachmentOption(option => option.setName('screenshot').setDescription('Upload a screenshot').setRequired(true))
    .addStringOption(option => option.setName('other_drivers').setDescription('Enter all drivers with @').setRequired(true))
    .addStringOption(option => option.setName('passengers').setDescription('Enter all passengers with @').setRequired(true)),
  async execute(interaction) {
    const author = interaction.user;
    const drivers = interaction.options.getString('other_drivers');
    const passengers = interaction.options.getString('passengers');
    const attachment = interaction.options.getAttachment('screenshot');
    const passengersWithDots = passengers.split(' ').map(passengers => `• ${passengers}`).join('\n');
    const driversWithDots = drivers.split(' ').map(driver => `• ${driver}`).join('\n');
    const driversWithMention = `• ${author}\n${driversWithDots}`;

    const embed = new EmbedBuilder()
      .setTitle('**Report System Rules**')
      .setColor('Yellow')
      .setDescription(`${driversWithMention}\n\nPassenger(s)\n${passengersWithDots}`)
      .setImage(attachment.url);

    const selectMenu1 = new SelectMenuBuilder()
      .setCustomId('select_menu1')
      .setPlaceholder('Select an option')
      .addOptions([
        {
          label: 'Option 1',
          value: 'option_1',
        },
        {
          label: 'Option 2',
          value: 'option_2',
        },
      ]);

    const selectMenu2 = new SelectMenuBuilder()
      .setCustomId('select_menu2')
      .setPlaceholder('Select another option')
      .addOptions([
        {
          label: 'Option A',
          value: 'option_a',
        },
        {
          label: 'Option B',
          value: 'option_b',
        },
      ]);

    const button1 = new ButtonBuilder()
      .setCustomId('button1')
      .setLabel('Button 1')
      .setStyle('Primary');

    const button2 = new ButtonBuilder()
      .setCustomId('button2')
      .setLabel('Button 2')
      .setStyle('Danger');

    const row1 = new ActionRowBuilder()
      .addComponents(selectMenu1, selectMenu2);

    const row2 = new ActionRowBuilder()
      .addComponents(button1, button2);

    await interaction.reply({
      embeds: [embed],
      ephemeral: true,
      components: [row1, row2],
    });
  },
};

在这里,我试图将 Select 菜单添加到操作行,然后发送它,但出现了一些错误.

错误消息:

data.components[0].components[1][COMPONENT_LAYOUT_WIDTH_EXCEEDED]: The specified component exceeds the maximum width
    at handleErrors (C:\Users\abodah\Desktop\shawarma\node_modules\@discordjs\rest\dist\index.js:640:13)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async BurstHandler.runRequest (C:\Users\abodah\Desktop\shawarma\node_modules\@discordjs\rest\dist\index.js:736:23)
    at async REST.request (C:\Users\abodah\Desktop\shawarma\node_modules\@discordjs\rest\dist\index.js:1387:22)
    at async ChatInputCommandInteraction.reply (C:\Users\abodah\Desktop\shawarma\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:111:5)
    at async Object.execute (C:\Users\x\Desktop\shawarma\commands\bus.js:69:5)
    at async Client.<anonymous> (C:\Users\x\Desktop\shawarma\bot.js:76:5) {
  requestBody: { files: [], json: { type: 4, data: [Object] } },
  rawError: {
    message: 'Invalid Form Body',
    code: 50035,
    errors: { data: [Object] }
  },
  code: 50035,
  status: 400,
  method: 'POST',

谁能帮帮我,给我解释一下?

我想发送嵌入菜单,然后添加2个 Select 菜单和2个按钮.

推荐答案

无法在操作行中添加多个 Select 菜单.如果您有多个 Select 菜单,则每个菜单都需要自己的操作行.这是一张limitation of the Discord API美元的.

另一个类似的规则是,包含 Select 菜单的操作行不能也包含按钮.

您可以做的是将它们发送到不同的操作行中:

const row1 = new ActionRowBuilder().addComponents(selectMenu1);
const row2 = new ActionRowBuilder().addComponents(selectMenu2);
const row3 = new ActionRowBuilder().addComponents(button1, button2);

await interaction.reply({
  embeds: [embed],
  ephemeral: true,
  components: [row1, row2, row3],
});

Javascript相关问答推荐

获取最接近的父项(即自定义元素)

在HTML中使用脚本变量作为背景图像源

使用JavaScript重命名对象数组中的键

调用SEARCH函数后,程序不会结束

Vue Quill css仅应用于我的第一个Quill Editor组件+如何自定义工具栏

强制执行useStatego struct 化变量[foo,setFoo]的命名约定?

脚本.js:3:20未捕获的类型错误:无法读取空的属性(读取addEventHandler)

我试图实现用户验证的reduxstore 和操作中出了什么问题?

GrapeJS -如何保存和加载自定义页面

类型自定义lazy Promise. all

Next.js(react)使用moment或不使用日期和时间格式

如何在Javascript中使用Go和检索本地托管Apache Arrow Flight服务器?

v—自动完成不显示 Select 列表中的所有项目

为什么Mutations 观察器用微任务队列而不是macrotask队列处理?

制作钢琴模拟器,并且在控制台中不会执行或显示该脚本

Eval vs函数()返回语义

从Nextjs中的 Select 项收集值,但当单击以处理时,未发生任何情况

第三方包不需要NODE_MODULES文件夹就可以工作吗?

为什么我看到的是回复,而不是我的文档?

Promise.race()返回已解析的promise ,而不是第一个被拒绝的promise