【问题标题】:Can someone help me fix this?有人可以帮我解决这个问题吗?
【发布时间】:2023-03-19 15:27:02
【问题描述】:

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

这是我的代码:

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);
});

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

【问题讨论】:

  • 所有这意味着第一个嵌入字段中没有值。

标签: javascript node.js bots discord.js undefined


【解决方案1】:

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

由于embed.fields 为空(尽管仍定义),因此触发了错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多