Discord.js v13使用embed报MODULE_NOT_FOUND错误如何解决?
修复方案
报错原因说明
你遇到的MODULE_NOT_FOUND报错核心是Discord.js依赖安装损坏、存在嵌套依赖冲突,同时你的测试代码存在两处语法错误,叠加导致功能无法运行。
分步修复操作
- 清理损坏依赖:删除项目根目录、commands目录下所有的
node_modules文件夹,以及根目录的package-lock.json文件。在项目根目录(即Discord Music Bot文件夹)打开终端,执行命令重新安装对应版本依赖:
npm install discord.js@13
不要在commands等子目录单独执行npm install安装依赖,避免出现嵌套依赖冲突。
- 修复导入语法错误:你的
MessageEmbed导入写法错误,它是discord.js的导出子模块,需要使用解构导入,将首行代码改为:
const { MessageEmbed } = require('discord.js');
- 修复未定义变量错误:你的代码中直接调用
channel.send()但未定义channel变量,需要使用消息上下文的频道对象,将发送代码改为:
message.channel.send({ embeds: [exampleEmbed] });
修复后完整代码
const { MessageEmbed } = require('discord.js'); module.exports = { name: 'embed', description: "example embed to test to see if it works lmao", execute(message, args){ const exampleEmbed = new MessageEmbed() .setColor('#0099ff') .setTitle('Some title') .setURL('https://discord.js.org/') .setAuthor('Some name', 'https://i.imgur.com/AfFp7pu.png', 'https://discord.js.org') .setDescription('Some description here') .setThumbnail('https://i.imgur.com/AfFp7pu.png') .addFields( { name: 'Regular field title', value: 'Some value here' }, { name: '\u200B', value: '\u200B' }, { name: 'Inline field title', value: 'Some value here', inline: true }, { name: 'Inline field title', value: 'Some value here', inline: true }, ) .addField('Inline field title', 'Some value here', true) .setImage('https://i.imgur.com/AfFp7pu.png') .setTimestamp() .setFooter('Some footer text here', 'https://i.imgur.com/AfFp7pu.png'); message.channel.send({ embeds: [exampleEmbed] }); } }
内容的提问来源于stack exchange,提问作者NaturalTwitch
相关产品推荐
相关产品推荐

