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

Discord执行slash命令后MessageButton弹窗未正常显示问题求助

问题原因

你遇到的问题是discord.js版本不匹配导致的组件写法过时:v14及以上版本已经将MessageActionRow、MessageButton废弃,替换为新的构造类,且按钮样式不再支持直接传字符串参数。

修复步骤

1. 修改导入语句

将原来的组件导入替换为v14对应API:

// 替换原来的const { MessageActionRow, MessageButton } = require('discord.js');
const { ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js');

2. 调整组件构造逻辑

按新API规范修改菜单行和按钮的构造代码:

async execute(interaction, client) {
    const row = new ActionRowBuilder()
        .addComponents(
            new ButtonBuilder()
                .setCustomId('dice-bag')
                .setLabel('danger')
                .setStyle(ButtonStyle.Danger),
            new ButtonBuilder()
                .setCustomId('spells')
                .setLabel('primary')
                .setStyle(ButtonStyle.Primary),
            new ButtonBuilder()
                .setCustomId('inventory')
                .setLabel('Success')
                .setStyle(ButtonStyle.Success),
        );
    await interaction.reply({content: 'Main menu', components: [row]})
}

3. 额外检查项

  • 确保你的discord.js版本为v14以上,运行npm i discord.js@latest可更新到最新稳定版
  • 无需额外添加Embed即可正常显示按钮,你原有的interaction.reply参数写法没有错误
  • 如果使用v13版本的discord.js,保持原来的MessageActionRow、MessageButton写法即可,按钮样式传字符串无需调整,更新依赖到对应稳定版即可解决报错

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.29 08:15:07