【发布时间】: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