无法读取未定义的属性“包含"

2022-01-10 00:00:00 node.js javascript discord.js

我是 JavaScript 新手,我是在尝试剖析嵌入的消息.这是我的代码,它可以正常运行几分钟,相应地工作,但我知道出了什么问题.

I am new to JavaScript, am I was trying to dissect an embedded message. Here's my code, it runs fine for a few mins, works accordingly but idk what goes wrong.

bot.on('message', (message) => {
  for (var i = 0; i < message.embeds.length; i++) {
    if (message.embeds[i].title.includes("text!")) {
      message.channel.send('reply')
    }
  }
})

推荐答案

我认为这段代码可以解决这个问题.

I think this code can fix this problem.


bot.on('message', (message) => {
  for (var i = 0; i < message.embeds.length; i++) {
    if (message.embeds[i] && message.embeds[i].title.includes("text!")) {
      message.channel.send('reply')
    }
  }
})

相关文章