我正试图从一个房间中获取多个消息。有些消息可能已经被删除了,所以试图获取它们会导致一个错误......。
const keyPromises = data.map(async(pack) => {
return new Promise((resolve, reject) => {
console.log("Checking " + pack.msgID);
client.guilds.cache.find(g => g.name === mainGuild).channels.cache.find(c => c.name === 'room').messages.fetch(pack.msgID)
.then(fetched => {
// Nothing is printed after catching the first error... Why?
console.log(fetched.attachments.first().url);
resolve(fetched.attachments.first().url + '\n');
})
.catch(() => {
console.log("> " + pack.msgID + " was not found!");
resolve("");
// it doesn't continue checking the other ids after catching the first error. Why?!
});
});
});
问题是映射函数在捕捉到第一个错误后挂起,即使它应该继续执行......。
输出。
Checking 707897580784320605
Checking 707899109477974037
Checking 710851524217143336
Checking 716151973291884575
> 707897580784320605 was not found!
先谢谢你
我被discord限制了速率。我通过在承诺中加入超时来解决这个问题。谢谢大家。