Get All users banners

So im trying to get all banners of server members.. what im doing is fetching all members let members = await guild.members.fetch(); but all the members here have banners as null. ik they need to be force fetched. so i tried something like this
let banners = [];
members.forEach(async (member) => {
const user = await member.fetch({ force: true });
console.log(user.banner)
if (user.banner) banners.push(user.banner)
})
let banners = [];
members.forEach(async (member) => {
const user = await member.fetch({ force: true });
console.log(user.banner)
if (user.banner) banners.push(user.banner)
})
but it still gives the same output
25 Replies
d.js toolkit
d.js toolkit17mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Post the full error stack trace, not just the top part! - Show your code! - Explain what exactly your issue is. - Not a discord.js issue? Check out #useful-servers. - Issue solved? Press the button!
Unknown User
Unknown User17mo ago
Message Not Public
Sign In & Join Server To View
Youssef
YoussefOP17mo ago
Thanks! I'll give it a try mmh it still give me an empty array
Unknown User
Unknown User17mo ago
Message Not Public
Sign In & Join Server To View
d4
d417mo ago
make sure to use for await
Youssef
YoussefOP17mo ago
Yes no problem, so it's a custom bot for somoene it just get all users banners and every 1 days using cron it send a random banner in a channel
Youssef
YoussefOP17mo ago
yes ofc, well it worked but i want a better way to do that
Youssef
YoussefOP17mo ago
what i thinked of is something like client.users.fetch({force: true}) but thats dont exist
d4
d417mo ago
not sure what you mean by "better way"
Unknown User
Unknown User17mo ago
Message Not Public
Sign In & Join Server To View
Youssef
YoussefOP17mo ago
i mean this spammy like jo said but maybe an interval of 5 minutes can help? i have an idea
Syjalo
Syjalo17mo ago
You can just specify the members you want to fetch.
members.fetch({ user: [1, 2, 3] });
members.fetch({ user: [1, 2, 3] });
Or just fetch all members
Youssef
YoussefOP17mo ago
well i just need 1 banner so i'll make it stop when i get1 banner
Syjalo
Syjalo17mo ago
Btw I don't think your members is an async iterator, so you don't need for await
d4
d417mo ago
await is for the client.users.fetch
Youssef
YoussefOP17mo ago
well i just tested now it work with only for
d4
d417mo ago
alright
Youssef
YoussefOP17mo ago
does this make only one request?
Syjalo
Syjalo17mo ago
Yes
Youssef
YoussefOP17mo ago
o
Syjalo
Syjalo17mo ago
But for that you need GuildMembers intent
Youssef
YoussefOP17mo ago
i did this for now
Youssef
YoussefOP17mo ago
Youssef
YoussefOP17mo ago
i think the break method don't work great cause it gonna give the same banner every time:= i need to make a function that shuffle the members collection
d.js docs
d.js docs17mo ago
method Collection#random() Obtains unique random value(s) from this collection.
Want results from more Discord servers?
Add your server