Han75
Han75

Reputation: 3

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

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?

Upvotes: 0

Views: 30008

Answers (1)

lieuwe_berg
lieuwe_berg

Reputation: 473

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

Upvotes: 1

Related Questions