richembed fields may not be empty 错误——我该如何解决这个问题?
richembed fields may not be empty error -- How would I fix this?
我的控制台不断收到错误消息,指出 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
非常感谢您的帮助!提前致谢!
您不能将整个对象作为值添加到 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 });
}
首先,确保提供args[1]
。然后,假设 args
中的第一个字符串是命令,将 suggestion
的声明更改为...
const suggestion = args.slice(1).join(' ');
编辑: 还将建议字段的行更改为...
.addField('Suggestion', suggestion.length <= 1024 ? suggestion : suggestion.slice(0, 1020) + '...')
这将防止任何导致 suggestion
对于嵌入字段来说太长的错误。
我的控制台不断收到错误消息,指出 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
非常感谢您的帮助!提前致谢!
您不能将整个对象作为值添加到 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 });
}
首先,确保提供args[1]
。然后,假设 args
中的第一个字符串是命令,将 suggestion
的声明更改为...
const suggestion = args.slice(1).join(' ');
编辑: 还将建议字段的行更改为...
.addField('Suggestion', suggestion.length <= 1024 ? suggestion : suggestion.slice(0, 1020) + '...')
这将防止任何导致 suggestion
对于嵌入字段来说太长的错误。