简体   繁体   English

Discord.js v13 [EMBED_FIELD_VALUE]:MessageEmbed 字段值必须是非空字符串

[英]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.rolesCollection ,而不是 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.

相关问题 Discord.js v13 错误:RangeError [EMBED_FIELD_VALUE]:MessageEmbed 字段值必须是非空字符串 - Discord.js v13 error: RangeError [EMBED_FIELD_VALUE]: MessageEmbed field values must be non-empty strings Discord bot 无法创建嵌入 RangeError [EMBED_FIELD_VALUE]:MessageEmbed 字段值必须是非空字符串 - Discord bot not able to create the embed RangeError [EMBED_FIELD_VALUE]: MessageEmbed field values must be non-empty strings discord.js V.13 嵌入问题 - RangeError [EMBED_FIELD_NAME]:MessageEmbed 字段名称必须是非空字符串。 - 特别是“成员自:”字段 - discord.js V.13 Embed Issue - RangeError [EMBED_FIELD_NAME]: MessageEmbed field names must be non-empty strings. - Specifically "Member Since:" field RangeError [EMBED_FIELD_VALUE]:MessageEmbed 字段值必须是非空字符串 - RangeError [EMBED_FIELD_VALUE]: MessageEmbed field values must be non-empty stringss Discord.js v12 禁止命令 - UnhandledPromiseRejectionWarning: RangeError [EMBED_FIELD_VALUE]: MessageEmbed 字段值不能为空 - Discord.js v12 Ban Command - UnhandledPromiseRejectionWarning: RangeError [EMBED_FIELD_VALUE]: MessageEmbed field values may not be empty [Discord.js]MessageEmbed 字段值必须是非空字符串 - [Discord.js]MessageEmbed field values must be non-empty strings MessageEmbed 字段值必须是非空字符串 - MessageEmbed field values must be non-empty strings MessageEmbed 字段值必须是非空字符串 gamedig 问题 - MessageEmbed field values must be non-empty strings gamedig problem RangeError [MESSAGE_CONTENT_TYPE]: 消息内容必须是非空字符串。 (discord.js v13) - RangeError [MESSAGE_CONTENT_TYPE]: Message content must be a non-empty string. (discord.js v13) Discord.js V13中如何编辑embed字段值 - How to edit embed field value in Discord.js V13
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM