How to fetch all members of a large guild discord.js

23,442

Assuming you're on the latest stable version (v12), you can use GuildMemberManager#fetch with no arguments to fetch all members of a guild.

Share:
23,442
Admin
Author by

Admin

Updated on December 20, 2022

Comments

  • Admin
    Admin over 1 year

    I am trying to fetch the ids of all members of a large guild. This guild has around 2000 people in it. I am using this:

    const list = client.guilds.get("id"); 
    list.fetchMembers().then(r => {
    
        r.members.array().forEach(r => {
        let userid = r.id        
        msg.channel.send(userid)
        })
    });
    

    It works for my test guild of 3 people but once I try it with the large guild, I get this error

    (node:8632) UnhandledPromiseRejectionWarning: Error: Members didn't arrive in time.
    at Timeout._onTimeout (c:\Users\Han75\Documents\bot\node_modules\discord.js\src\client\Client.js:436:7)
    at listOnTimeout (internal/timers.js:531:17)
    at processTimers (internal/timers.js:475:7)
    

    I know its because of a timeout. How do I stop this?