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 toolkit2y 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 User2y ago
Message Not Public
Sign In & Join Server To View
Youssef
YoussefOP2y ago
Thanks! I'll give it a try mmh it still give me an empty array
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
d4
d42y ago
make sure to use for await
Youssef
YoussefOP2y 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
YoussefOP2y ago
yes ofc, well it worked but i want a better way to do that
Youssef
YoussefOP2y ago
what i thinked of is something like client.users.fetch({force: true}) but thats dont exist
d4
d42y ago
not sure what you mean by "better way"
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Youssef
YoussefOP2y ago
i mean this spammy like jo said but maybe an interval of 5 minutes can help? i have an idea
Syjalo
Syjalo2y 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
YoussefOP2y ago
well i just need 1 banner so i'll make it stop when i get1 banner
Syjalo
Syjalo2y ago
Btw I don't think your members is an async iterator, so you don't need for await
d4
d42y ago
await is for the client.users.fetch
Youssef
YoussefOP2y ago
well i just tested now it work with only for
d4
d42y ago
alright
Youssef
YoussefOP2y ago
does this make only one request?
Syjalo
Syjalo2y ago
Yes
Youssef
YoussefOP2y ago
o
Syjalo
Syjalo2y ago
But for that you need GuildMembers intent
Youssef
YoussefOP2y ago
i did this for now
Youssef
YoussefOP2y ago
Youssef
YoussefOP2y 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 docs2y ago
method Collection#random() Obtains unique random value(s) from this collection.
Want results from more Discord servers?
Add your server