Cannot read property 'includes' of undefined

前端 未结 6 1309
抹茶落季
抹茶落季 2021-01-21 16:09

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.



        
6条回答
  •  北恋
    北恋 (楼主)
    2021-01-21 16:14

    You can write your code more defensive like this. Instead of

    if(message.embeds[i].title.includes("text!"))
    

    you can write the following

    if(typeof message.embeds[i].title === "string" &&
    message.embeds[i].title.includes("text!"))
    

提交回复
热议问题