Javascript richembed字段可能不是空的错误--如何修复此错误?
我的控制台上不断出现一个错误,说RichEmbed字段可能不是空的。当我为每个字段定义了值时。。。代码如下:Javascript richembed字段可能不是空的错误--如何修复此错误?,javascript,node.js,discord.js,Javascript,Node.js,Discord.js,我的控制台上不断出现一个错误,说RichEmbed字段可能不是空的。当我为每个字段定义了值时。。。代码如下: if (cmd === `${prefix}suggest`) { // USAGE: // /suggest this is the suggestion const suggestion = args.join(' ').slice(22); const suggestEmbed = new Discord.RichEmbed() .setDescri
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
我会很感激你的帮助!提前谢谢你 不能将整个对象作为值添加到RichEmbed中。您试图将通道对象作为RichEmbed值输入,这是不允许的 我想您想将
频道.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 });
}
首先,确保提供了
args[1]
。然后,假设args
中的第一个字符串是命令,将suggestion
的声明更改为
const suggestion=args.slice(1.join)(“”);
编辑:同时将建议字段的行更改为
.addField('Suggestion',Suggestion.length`.addField('Suggestion',Suggestion)
那么建议
只是一个建议,但如果你加入公会并在那里提出其中一些问题可能会更好。我只是根据你提出的最后3个问题来回答。在为你使用的库设计的社区中可能更容易获得快速反馈。我想你应该这样做:suggestion=args.join(“”)
,因为.slice(22)
是一种“廉价且愚蠢”的删除提及的方式。这是真的。现在我改变了使用信息的方式#提及感谢:D