becuase sum_messages
will never be greater or same as limit
because it's not a number, it must be sum_messages.length
and a check after getting the messages if(messages.size === 0)
would also not hurt
async function lots_of_messages_getter(channel, limit = 6000) {
const sum_messages = [];
let last_id;
while (true) {
const options = { limit: 100 };
if (last_id) {
options.before = last_id;
}
const messages = await channel.messages.fetch(options);
if (messages.size === 0) {
break;
}
sum_messages.push(...messages.array());
last_id = messages.last().id;
if (messages.size != 100 || sum_messages.length >= limit) {
break;
}
}
return sum_messages;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…