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