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

Discord.js v14选择菜单交互失败:选中选项仅提示失败无响应

问题:discord.js v14 StringSelectMenu选中后交互失败无反馈

我创建了一个StringSelectMenu,选中菜单项时本应发送包含信息的Embed,但实际仅显示“This interaction failed”,控制台无任何报错信息。使用的是discord.js v14版本,代码如下:

const {SlashCommandBuilder, ActionRowBuilder , StringSelectMenuBuilder, EmbedBuilder,} = require("discord.js");

module.exports = {
data: new SlashCommandBuilder()
    .setName('test')
    .setDescription('ทดสอบ'),
async execute  (interaction)  {
    const menu = new ActionRowBuilder()
    .addComponents(
        new StringSelectMenuBuilder()
        .setCustomId('select')
        .setPlaceholder('noting select game')
        .addOptions(
                {
                    label: 'BF',
                    description: "Test",
                    value: "OPT 1"
                },
                {
                    label: 'City Thailand',
                    description: "Test",
                    value: "OPT 2"
                },
            ),
        );

    await interaction.reply({ content: "you select", components: [menu]})
}
}

选中选项后无任何反馈效果,交互失败截图:
交互失败提示


解决方案

你的代码只实现了下拉菜单的创建与发送,但没有监听菜单的交互事件,Discord无法找到对应的处理逻辑,因此触发交互失败提示。

需要在客户端的interactionCreate事件中添加对该下拉菜单的响应逻辑,完整示例如下:

1. 保留原命令文件代码不变

2. 在客户端主文件(如index.js)中添加交互监听

const { Client, GatewayIntentBits, EmbedBuilder } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds] });

// 监听交互事件
client.on('interactionCreate', async interaction => {
  // 过滤非下拉菜单的交互
  if (!interaction.isStringSelectMenu()) return;

  // 匹配自定义ID为'select'的菜单
  if (interaction.customId === 'select') {
    // 根据选中值生成对应Embed
    let embed;
    switch (interaction.values[0]) {
      case 'OPT 1':
        embed = new EmbedBuilder()
          .setTitle('BF选项')
          .setDescription('你选择了BF选项')
          .setColor('#0099ff');
        break;
      case 'OPT 2':
        embed = new EmbedBuilder()
          .setTitle('City Thailand选项')
          .setDescription('你选择了City Thailand选项')
          .setColor('#ff9900');
        break;
      default:
        embed = new EmbedBuilder()
          .setTitle('未知选项')
          .setDescription('未识别的选择')
          .setColor('#ff0000');
    }

    // 响应交互:更新原消息为Embed,同时移除菜单
    await interaction.update({ embeds: [embed], components: [], content: '' });
    // 若需要单独发送消息而非更新,可使用:
    // await interaction.reply({ embeds: [embed], ephemeral: true });
  }
});

client.login('你的Bot令牌');

关键说明

  • 必须通过interactionCreate事件监听所有交互,筛选出StringSelectMenu类型的交互
  • 通过customId精准匹配需要处理的下拉菜单
  • 处理完成后必须调用interaction.update()或interaction.reply()响应,否则Discord会在3秒后判定交互超时失败

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.27 03:05:27