我的控制台上不断出现错误,提示 RichEmbed 字段可能不为空。当我为每个字段定义了值时...以下是代码:
if (cmd === `${prefix}suggest`) {
// USAGE:
// /suggest this is the suggestion
const suggestion = args.join(' ').slice(22);
const suggestEmbed = new Discord.RichEmbed()
.setDescription('~~-------~~**__NEW SUGGESTION!__**~~-------~~')
.setColor('#ff0000')
.addField('Suggestion By', `${message.author} (${message.author.id})`)
.addField('Channel', message.channel)
.addField('Time', message.createdAt)
.addField('Suggestion', suggestion)
.setTimestamp()
.setFooter('Use /invite to invite me to your server!');
const suggestchannel = message.guild.channels.find(`name`, 'suggestions');
if (!suggestchannel) return message.channel.send("Couldn't find suggestions channel. Please **create one for this command to work!**");
message.delete().catch(O_o => {});
suggestchannel.send({ embed: suggestEmbed });
}
这是错误:
(node:616) UnhandledPromiseRejectionWarning: RangeError: RichEmbed field values may not be empty.
at RichEmbed.addField
我希望得到一些帮助!预先感谢您!
最佳答案
首先,确保提供了args[1]
。然后,假设 args 中的第一个字符串是命令,将 suggestion
的声明更改为...
const suggestion = args.slice(1).join(' ');
编辑:还将建议字段的行更改为...
.addField('Suggestion', suggestion.length <= 1024 ? suggestion : suggestion.slice(0, 1020) + '...')
这将防止任何导致建议
对于嵌入字段来说太长的错误。
关于javascript - richembed 字段可能不为空错误 -- 我该如何解决这个问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55559630/