我在控制台上不断收到错误消息,说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
我将感谢您的帮助!预先谢谢你!
答案 0 :(得分:0)
您不能在RichEmbed中添加整个对象作为值。您正在尝试输入渠道对象作为RichEmbed值,这是不允许的。
我想您想将channel.name
添加到此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.name)
.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 });
}
答案 1 :(得分:0)
首先,请确保提供了args[1]
。然后,假设args
中的第一个字符串为命令,请将suggestion
的声明更改为...
const suggestion = args.slice(1).join(' ');
编辑:还将建议字段的行更改为...
.addField('Suggestion', suggestion.length <= 1024 ? suggestion : suggestion.slice(0, 1020) + '...')
这将防止导致suggestion
对于嵌入字段过长的错误。