#<Collection>.each
21 messages · Page 1 of 1 (latest)
just do let memberArray = […role.members.values()]
its three points not triple points
Just use .map()
oh, but I think this method doesn't allow me to get specific data like those I want.
same problem as .each
u want to return you own obj?
yep
Your js is terrible
let membersO = role.members.map(m => ({
id: m.id,
avatarURL: m.displayAvatarURL(),
displayName: m.displayName,
displayHexColor: m.displayHexColor,
}));
staff.push(...membersO);
Umm, that js doesn’t do what they want it to do though…
Is that in an async function? And do you await its call before proceeding?
oh yes I was sleepy. membersO == staff.
yeah it's and I don't await it's call for some reasons, the code is currently look like this:
async function staffCache(client) {
const guild = await client.guilds.fetch(serverID);
let staff = []
for (i = 0; i < staffRoles.length; i++) {
const role = await guild.roles.fetch(staffRoles[i][1]);
let members = [...role.members.values()];
staff.push(members.map(m=> ({id : m.id})));
};
await redisClient.set('staffData', JSON.stringify(staff));
console.log('staff data have been updated.');
setTimeout(()=>{staffCache(client)}, 60000 * 60);
}
the code is working fine, but the problem is that it does not show all the members who have these roles for unknown reasons.
output:
[
[ { id: '193133466349469696' } ],
[],
[],
[ { id: '222251985200611328' } ],
[ { id: '222251985200611328' } ],
[],
[ { id: '483265262611857409' } ],
[ { id: '323999863153098752' } ],
[
{ id: '899265348178694184' },
{ id: '491352435223298058' },
{ id: '962943798940434452' }
],
[ { id: '640847325945921536' } ]
]
the members having these roles are much more than those showing up
Fetching a role doesnt mean that it will populate role.members
You would need to fetch all members from the guild using guild.members.fetch
oh shit
And collection.map exists