axios.get(`https://api.vk.com/method/wall.get?owner_id=-182911711&count=1&extended=1&access_token=токен&v=5.60`).then(res => {
return res.data;
}).then(data => {
let text = data.response.items[0].text;
let time = data.response.items[0].date;
let attachments = data.response.items[0].attachments[0].type;
if (news.news == time) {
console.log(`Новых новостей нет!`)
} else {
if (attachments == "photo") {
const msg = new webhook.MessageBuilder()
.setName("Steve")
.setColor("#aabbcc")
.addField(data.response.groups[0].name, text)
.setImage(data.response.items[0].attachments[0].photo.photo_1280)
.setTime();
Hook.send(msg);
news.news = `${time}`
} else {
const msg = new webhook.MessageBuilder()
.setName("Steve")
.setColor("#aabbcc")
.addField(data.response.groups[0].name, text)
.setTime();
Hook.send(msg);
}
}
}).catch(err => console.log(err));
В ответе json
data.response.items[0].attachments[0].type
может не существовать и код не будет выполнятся дальше
let attachments = data.response.items[0].attachments[0].type;
, необходимо если data.response.items[0].attachments[0].type; = undefindet устанавливать значение для него 0