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

Discord.js V13出现MessageActionRow is not a constructor报错求助

问题原因

核心报错的直接诱因是discord.js版本不匹配,同时代码存在几处书写错误:

  • 你声明使用v13版本,但实际本地安装的是v14及以上版本:discord.js v14重构了组件相关API,MessageActionRow被重命名为ActionRowBuilder,且导出路径从根包调整到builders子模块,直接从根包导入MessageActionRow会拿到undefined,调用new关键字就会抛出「不是构造函数」的错误。
  • 按钮样式拼写错误:代码中写的PRIMAMRY多了一个M,正确拼写为PRIMARY。
  • 消息发送参数名错误:message.channel.send接收的嵌入参数名为embeds、组件参数名为components,都是复数形式,你写的单数形式会导致内容不渲染。
解决方案

根据你要使用的版本二选一即可:

方案1:继续使用Discord.js v13

  1. 先执行命令安装正确的v13版本:
    npm install discord.js@13.x
  2. 修正代码里的拼写和参数错误即可,修改后的命令文件代码如下:
// command 
const {
    MessageActionRow,
    MessageButton
} = require('discord.js');
module.exports = {
    name: 'commands',
    permissions: [],
    description: "this sends help!",
    aliases: ['cmd', 'cmdinfo', 'commandsinfo'],
    execute(client, message, cmd, args, Discord) {
            const utilbtn = new MessageActionRow()
                .addComponents(
                    new MessageButton()
                    .setCustomId('primary')
                    .setLabel('Primary')
                    .setStyle('PRIMARY'),
                    
                );
            const newEmbed = new Discord.MessageEmbed()
                .setTitle('**Commands**')
            message.channel.send({
                embeds: [newEmbed],
                components: [utilbtn]
            });
        }
    }
}

方案2:升级使用Discord.js v14

  1. 先执行命令安装最新版discord.js:
    npm install discord.js@latest
  2. 按照v14的API规范修改组件导入和调用逻辑,修改后的命令文件代码如下:
// command 
const {
    ActionRowBuilder,
    ButtonBuilder,
    ButtonStyle,
    EmbedBuilder
} = require('discord.js');
module.exports = {
    name: 'commands',
    permissions: [],
    description: "this sends help!",
    aliases: ['cmd', 'cmdinfo', 'commandsinfo'],
    execute(client, message, cmd, args, Discord) {
            const utilbtn = new ActionRowBuilder()
                .addComponents(
                    new ButtonBuilder()
                    .setCustomId('primary')
                    .setLabel('Primary')
                    .setStyle(ButtonStyle.Primary),
                    
                );
            const newEmbed = new EmbedBuilder()
                .setTitle('**Commands**')
            message.channel.send({
                embeds: [newEmbed],
                components: [utilbtn]
            });
        }
    }
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.05 01:48:03