我有这个错误
<块引用>UnhandledPromiseRejectionWarning: TypeError: 无法读取未定义的属性 'map' 在 C:\Users\Misha\Desktop\slaves\test2.js:23:18
<块引用>在 processTicksAndRejections (internal/process/task_queues.js:93:5)
<块引用>在异步 Timeout.buyFetter [as _onTimeout] (C:\Users\Misha\Desktop\slaves\test2.js:16:5)
你能帮我吗? 这是我的代码:
async function buyFetter() {
await fetch("https://pixel.w84.vkforms.ru/HappySanta/slaves/1.0.0/start", {
method: "GET",
headers: {
"Content-Type": "application/json",
authorization: config.authorization
}
}).then(a => a.json()).then(a => {
a.slaves.map(async b => {
if (0 === b.fetter_to) await axios.post("https://pixel.w84.vkforms.ru/HappySanta/slaves/1.0.0/buyFetter", {
slave_id: b.id
}, {
headers: {
authorization: config.authorization
}
}), vk.api.messages.send({
peer_id: config.vk.chat,
random_id: 0,
message: `Купил оковы для @id$ {
b.id
}`
});
else if ("" === b.job.name) {
let c = utils.pick(["утка", "@ut1ka"]);
await axios.post("https://pixel.w84.vkforms.ru/HappySanta/slaves/1.0.0/jobSlave", {
slave_id: b.id,
name: c
}, {
headers: {
authorization: config.authorization
}
}), vk.api.messages.send({
peer_id: config.vk.chat,
random_id: 0,
message: `Установил работу для @id$ {
b.id
} | Работа: $ {
c
}`
})
}
})
})
}
答案 0 :(得分:0)
You may need to have look of async/await usage.
async function buyFetter() {
try {
const res = await fetch("https://pixel.w84.vkforms.ru/HappySanta/slaves/1.0.0/start", {
method: "GET",
headers: {
"Content-Type": "application/json",
authorization: config.authorization
}
});
const data = await res.json();
data.slaves.map(async b => {
console.log(b);
})
} catch (err) {
console.log(err);
}
}