[英]Discord.js v13 [EMBED_FIELD_VALUE]: MessageEmbed field values must be non-empty strings
const key = `${message.guild.id}|${message.channel.id}|${message.id}`;
if (MESSAGE_CACHE.has(key)) {
const cachedMessage = MESSAGE_CACHE.get(key);
const logChannel = message.guild.channels.cache.get(settings.log_channel);
if (!logChannel) return;
const embed = new MessageEmbed()
.setAuthor("Ghost ping detected")
.setDescription(
`**Message**:
${cachedMessage.content}
**Author:** ${cachedMessage.author.tag} \`${cachedMessage.author.id}\`
**Channel:** <#${cachedMessage.channelId}>
`
)
.addField("Members", cachedMessage.mentions.members, true)
.addField("Roles", cachedMessage.mentions.roles, true)
.addField("Everyone?", cachedMessage.mentions.everyone, true)
.setFooter("Sent at: " + cachedMessage.createdAt);
sendMessage(logChannel, { embeds: [embed] });
}
If i delete a message with a ghost ping in it, it returns the error Unhandled Rejection at: RangeError [EMBED_FIELD_VALUE]: MessageEmbed field values must be non-empty strings.
如果我删除一条消息,其中包含幽灵 ping,它会返回错误
Unhandled Rejection at: RangeError [EMBED_FIELD_VALUE]: MessageEmbed field values must be non-empty strings.
Any idea why this happeneds as the fields have valures知道为什么会发生这种情况,因为这些字段具有值
All the values you put there are not strings, so it will throw that error.你放在那里的所有值都不是字符串,所以它会抛出那个错误。 Also, note that
.mentions.members
and .mentions.roles
are Collection
s, not arrays, so you need to convert them.另请注意,
.mentions.members
和.mentions.roles
是Collection
,而不是 arrays,因此您需要转换它们。
.addField("Members", `${Array.from(cachedMessage.mentions.members.values()).join(", ") || "None"}`, true)
.addField("Roles", `${Array.from(cachedMessage.mentions.roles.values()).join(", ") || "None"}`, true)
.addField("Everyone?", `${cachedMessage.mentions.everyone}`, true)
.setFooter("Sent at: " + `${cachedMessage.createdAt}`);
On .addField
creating the error, to prevent this errors,在
.addField
创建错误,以防止此错误,
.addField("Members", `${cachedMessage.mentions.members || "Your word"}`, true)
.addField("Roles", `${cachedMessage.mentions.roles || "Your word"}`, true)
.addField("Everyone?", `${cachedMessage.mentions.everyone || "Your word"}`, true)
.setFooter("Sent at: " + cachedMessage.createdAt);
explanation: if your bot didn't get any members that pinged someone, instead of throwing an error, it will send a string
解释:如果你的机器人没有得到任何对某人执行 ping 命令的成员,它不会抛出错误,而是发送一个
string
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.