discord.js 中的“MessageEmbed 字段值可能不为空”问题

时间:2021-05-15 01:42:12

标签: discord discord.js

我目前正在 node.js 中制作一个 discord bot,并且不断遇到这个问题。我正在尝试创建一个帮助命令,但我想在执行命令之前尝试确保嵌入和内容正常工作,并且我不断收到这个奇怪的错误。我放了两个代码示例,一个是命令的代码,一个是使命令真正起作用的代码。有人可以帮忙吗?

module.exports = {
name: 'command',
description: "Commands for the bot!",
execute(message, args, Discord) {
    const newEmbed = new Discord.MessageEmbed()
    .setColor('#304281')
    .setTitle('Commands')
    .setURL('https://discord.com/terms')
    .setDescription('Showing commands..')
    .addFields(
        {name: 'Rule 1', value: ''},
        {name: 'Rule 1', value: ''},
        {name: 'Rule 1', value: ''}
    )
    .setImage('https://blog.logomyway.com/wp-content/uploads/2020/12/discord-mascot.png')
    .setFooter('Bot created by John Adams#7337');

    message.channel.send(newEmbed);
}

}

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 === 'botinfo'){
    client.commands.get('botinfo').execute(message, args);

} else if (command === 'test'){
    client.commands.get('test').execute(message, args);

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

});

这里是错误:

C:\Users\Chunko\Desktop\DiscordBot\node_modules\discord.js\src\structures\MessageEmbed.js:432
if (!value) throw new RangeError('EMBED_FIELD_VALUE');
            ^

RangeError [EMBED_FIELD_VALUE]:MessageEmbed 字段值不能为空。 在 Function.normalizeField (C:\Users\Chunko\Desktop\DiscordBot\node_modules\discord.js\src\structures\MessageEmbed.js:432:23) 在 C:\Users\Chunko\Desktop\DiscordBot\node_modules\discord.js\src\structures\MessageEmbed.js:452:14 在 Array.map() 在 Function.normalizeFields (C:\Users\Chunko\Desktop\DiscordBot\node_modules\discord.js\src\structures\MessageEmbed.js:451:8) 在 MessageEmbed.addFields (C:\Users\Chunko\Desktop\DiscordBot\node_modules\discord.js\src\structures\MessageEmbed.js:266:42) 在 Object.execute (C:\Users\Chunko\Desktop\DiscordBot\commands\command.js:11:10) 在客户端。 (C:\Users\Chunko\Desktop\DiscordBot\index.js:39:40) 在 Client.emit (events.js:315:20) 在 MessageCreateAction.handle (C:\Users\Chunko\Desktop\DiscordBot\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14) 在 Object.module.exports [as MESSAGE_CREATE] (C:\Users\Chunko\Desktop\DiscordBot\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32) { [符号(代码)]:'EMBED_FIELD_VALUE' }

1 个答案:

答案 0 :(得分:0)

这是一个非常简单的错误,你犯了一个非常大的错误。

在 Discord.js 中嵌入当您在嵌入中添加字段时,您应该添加到字段 1.Title Or the name of the field 和 2.The content or the value of the field.

但在您的情况下,您保留了第二个参数,即 value 为空。所以它删除了这个错误而不是 {name: 'Rule 1', value: ''} 你应该这样做 {name: 'Rule 1', value: 'Your rule here do not keep it empty'}