首页 > 解决方案 > 有人可以帮我解决这个问题吗?

问题描述

所以我做了一个不和谐的机器人,可以读取其他机器人嵌入并回复它

这是我的代码:

client.on("message", (message) => {
  let embed = message.embeds[0];
  if (
    message.author.id == "555955826880413696" &&
    embed &&
    embed.fields &&
    embed.fields[0].value.includes(
      "Type **CATCH** (once) to collect some coins! The reward depend on how much players join\n"
    )
  ) {
    message.channel
      .send(
        "<@&742328576237633546> " +
          "<a:coins:744946097558126662> " +
          "**CATCH** " +
          "<a:coins:744946097558126662>"
      )
      .catch(console.error);
  } else console.log(embed);
});

它工作得很好,但过了一段时间它崩溃并说: 错误信息

标签: javascriptnode.jsbotsdiscord.jsundefined

解决方案


embed.fields将要求从if语句更改为embed.fields[0]

错误正在触发,因为embed.fields它是空的(尽管仍然定义)。


推荐阅读