简体   繁体   中英

Can someone help me fix this?

So I've made a discord bot that can read other bot embed and reply it

Here's my code:

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

It worked nicely, but after sort of time it crashed and said: 错误信息

Change the embed.fields requirement from the if statement to embed.fields[0]

The error is triggering because embed.fields is empty (although still defined).

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM