繁体   English   中英

Discord.js 嵌入:TypeError:Discord.MessageEmbed 不是构造函数

[英]Discord.js embeds: TypeError: Discord.MessageEmbed is not a constructor

我最近尝试为我的不和谐机器人添加 MessageEmbed,但出现此错误:

类型错误:Discord.MessageEmbed 不是构造函数

我想知道是否有人知道如何解决这个问题,我尝试了一些我可以在网上找到的 rip,其中一些包括尝试重新安装 node.js 和 discord.js,其他提到了一种不同的方法,例如使用 NewMessageEmbed() 代替,但是他们都没有为我工作过,如果有比我多一点经验的人可以提供解决方案,那将是很棒的,我已经提供了所有涉及的代码和错误的屏幕截图,在此先感谢。

命令文件:

    module.exports = {
    name: 'command',
    description: "Embeds!",
    execute(message, args, Discord){
        const newEmbed = new Discord.MessageEmbed()
        .setColor('#FFA62B')
        .setTitle('Rules')
        .setURL('https://discord.gg/fPAsvEey2k')
        .setDescription('**This is an embed for the server rules.**')
        .addFields(
            {name: '1.', value: 'Treat everyone with respect. Absolutely no harassment, witch hunting, sexism, racism or hate speech will be tolerated.'},
            {name: '2.', value: 'No spam or self-promotion (server invites, advertisements, etc.) without permission from a staff member. This includes DMing fellow members.'},
            {name: '3.', value: 'No NSFW or obscene content. This includes text, images or links featuring nudity, sex, hard violence or other graphically disturbing content.'},
            {name: '4.', value: 'if you see something against the rules or something that makes you feel unsafe, let staff know. We want this server to be a welcoming space!'},
            {name: '5.', value: 'Keep public conversations in English.'},
            {name: '6.', value: 'This list is not exhaustive and will be updated as we see fit.'}


        )
        .setImage('./images/rules.png')
        .setFooter('Make sure to follow the rules');

        message.channel.send(newEmbed);
    }

}

主文件:

// grabs the discord.js bot file for import //
const {Client, Intents, Collection} = require('discord.js');

// create the client for the bot //
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });

// prefix to use for bot commands //
const prefix = '!';

const fs = require('fs');
const Discord = require('./commands/discord');

client.commands = new Collection();

const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
for(const file of commandFiles){
    const command = require(`./commands/${file}`);

    client.commands.set(command.name, command);
}


// log to console that the bot has successfully logged in //
client.once('ready', () => {
    console.log("Reformed Esports is online");
});

/* Command handler, checking if message starts with prefix and is not the bot,
 allowing commands to have multiple words */
client.on('message', message =>{
    if(!message.content.startsWith(prefix) || message.author.bot) return;

    const args = message.content.slice(prefix.length).split(/ +/);
    const command = args.shift().toLowerCase();

    if(command === 'ping'){
        client.commands.get('ping').execute(message, args);
    } else if(command === 'discord'){
        client.commands.get('discord').execute(message, args);
    } else if(command === 'pugs') {
        client.commands.get('pugs').execute(message, args);
    } else if(command === 'command'){
        client.commands.get('command').execute(message, args, Discord)
    }
});

// bot login using discord bot token //
client.login('blank');

完整错误的图像: 错误代码

您应该传递 discord.js 模块,而是传递一个文件。 这可能与 discord.js 模块具有不同的功能、属性等。

此代码将修复错误:

client.commands.get('command').execute(message, args, require('discord.js'))

此外,现在必须使用embeds属性发送embeds

message.channel.send({ embeds: [newEmbed] })

看起来您正在发送./commands/discord作为参数而不是真正的 discord.js 包。 我会将Embed添加到const {Client, Intents, Collection} = require('discord.js'); 和发送Embed代替Discord的内部client.commands.get('command').execute(message, args, Discord)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM