首页 > 解决方案 > 我正在尝试在 discord.js 中进行嵌入,但它不断给出错误

问题描述

module.exports = {
    name: 'clear',
    description: "Clears a select amount of messages",
    execute(message, args, Discord, amount=5){

        const newEmbed = new Discord.MessageEmbed()
        .setColor('#304281')
        .setTitle('Not enough power!')
        .setDescription('')
        .addFields(
            {name: '', value: 'You dont have the required permission to use this command'}
        )
        .setFooter('More Coming Soon!');

        if(message.member.permissions.has("MANAGE_MESSAGES" || "ADMINISTRATOR")){
            message.channel.send('this should clear messages lol')
        
        } else {
            channel.send(newEmbed);
        } 
    }
}

那是我尝试嵌入的代码。我不断收到的错误是:

“const newEmbed = 新的 Discord.MessageEmbed()

TypeError:无法读取未定义的属性“MessageEmbed”

任何帮助将不胜感激

标签: javascriptdiscord.js

解决方案


正如错误所暗示的,没有MessageEmbedundefined 的属性,这意味着 Discord 是未定义的。在文件的最顶部,在 上方module.exports = {,只需添加行const Discord = require('discord.js');.

即使您在主文件中导入了不和谐,您也没有在此文件中执行此操作,因此在该文件中未定义。在文件的最顶部添加该行会将其导入该文件,并且可以在文件中的任何位置使用。希望对您有所帮助。


推荐阅读