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.
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.
.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("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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.