【问题标题】:"MessageEmbed field values may not be empty" problem in discord.jsdiscord.js 中的“MessageEmbed 字段值可能不为空”问题
【发布时间】:2021-08-05 02:47:22
【问题描述】:

我目前正在 node.js 中制作一个不和谐的机器人并不断遇到这个问题。我正在尝试发出帮助命令,但我想在执行命令之前尝试确保嵌入和东西工作,并且我不断收到这个奇怪的错误。我放了两个代码示例,一个是命令的代码,一个是使命令实际工作的代码。有人可以帮忙吗?

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' }

【问题讨论】:

  • 非常自我解释,你有一个空字段值,看{name: 'Rule 1', value: ''},

标签: discord discord.js


【解决方案1】:

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

在 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'}

【讨论】:

    猜你喜欢
    • 2021-09-04
    • 2020-12-10
    • 2020-09-24
    • 2020-11-16
    • 2021-10-09
    • 2021-07-16
    • 2021-08-28
    • 2021-08-24
    • 2022-01-16
    相关资源
    最近更新 更多