Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

216
Views
Loop to workaround 100 message fetch limit no longer working after 1 day

I created a discord bot yesterday from this post to export fields from embeds and it was working fine but it's not working today. The error I'm getting is TypeError: messages.array is not a function I tried uninstalling node and reinstalling but to no avail. I sent the file to a friend to run and it worked perfectly so it seems to be a problem with my machine. I also tried to run it on my windows server and I did not see any errors but the bot failed at exporting the fields (I don't intend on using my server to run the bot, just used for troubleshooting). Has anyone seen this error before and/or have a solution?

More detailed Error (One message):

"xxxx@xxxx-mbp embed bot % node main /Users/xxxx/Downloads/embed bot/main.js:24 sum_messages.push(...messages.array()); ^

TypeError: messages.array is not a function at lots_of_messages_getter (/Users/xxxx/Downloads/embed bot/main.js:24:39) at processTicksAndRejections (node:internal/process/task_queues:96:5) at async Client. (/Users/xxxx/Downloads/embed bot/main.js:36:20)"

async function lots_of_messages_getter(channel, limit = 10000) {
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);
    sum_messages.push(...messages.array());
    last_id = messages.last().id;

    if (messages.size != 100 || sum_messages >= limit) {
        break;
    }
}

return sum_messages;

}

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Messages is a Collection, there is no array method for that object.

According to the documentation you can convert it to a regular array and then use the spread operator.

sum_messages.push(...Array.from(messages));
about 4 years ago · Juan Pablo Isaza Report

0

I changed “array” to “values” and it works perfectly now. Thanks to everyone that helped!

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!