Leaderboard problem

Hello i have this code:
setInterval(async function () {

const correctServer = client.guilds.cache.get("878417329833259048")

let leaderBoardMessage = "1000082958209790013"
let leaderboardChannel = correctServer.channels.cache.get("999854180879585421")

const leaderBoardMessageEdit = await leaderboardChannel.messages.fetch(leaderBoardMessage)

let membersHat = await correctServer.members.cache.filter(
(member) =>
member.nickname && member.nickname.toLowerCase().includes("šŸŽ©") ||
member.username && member.username.toLowerCase().includes("šŸŽ©")
);
if (membersHat.size === 0) console.log("No members found");

let countHat = 0;
membersHat.forEach((member) => {
countHat = countHat + 1;
});

let membersBone = await correctServer.members.cache.filter(
(member) =>
member.nickname && member.nickname.toLowerCase().includes("šŸ¦“")
);
if (membersBone.size === 0) console.log("No members found");

let countBone = 0;
membersBone.forEach((member) => {
countBone = countBone + 1;
});

let leaderBoardEmbed = new MessageEmbed()
.setTitle("Clan War Leaderboard")
.setDescription(`šŸŽ© - ${countHat} Members\n\nšŸ¦“ - ${countBone} Members`)
.setColor("BLUE")
.setFooter({ text: "Updating every 600 seconds!"})
return leaderBoardMessageEdit.edit({ embeds: [leaderBoardEmbed]

})
}, 600000);
setInterval(async function () {

const correctServer = client.guilds.cache.get("878417329833259048")

let leaderBoardMessage = "1000082958209790013"
let leaderboardChannel = correctServer.channels.cache.get("999854180879585421")

const leaderBoardMessageEdit = await leaderboardChannel.messages.fetch(leaderBoardMessage)

let membersHat = await correctServer.members.cache.filter(
(member) =>
member.nickname && member.nickname.toLowerCase().includes("šŸŽ©") ||
member.username && member.username.toLowerCase().includes("šŸŽ©")
);
if (membersHat.size === 0) console.log("No members found");

let countHat = 0;
membersHat.forEach((member) => {
countHat = countHat + 1;
});

let membersBone = await correctServer.members.cache.filter(
(member) =>
member.nickname && member.nickname.toLowerCase().includes("šŸ¦“")
);
if (membersBone.size === 0) console.log("No members found");

let countBone = 0;
membersBone.forEach((member) => {
countBone = countBone + 1;
});

let leaderBoardEmbed = new MessageEmbed()
.setTitle("Clan War Leaderboard")
.setDescription(`šŸŽ© - ${countHat} Members\n\nšŸ¦“ - ${countBone} Members`)
.setColor("BLUE")
.setFooter({ text: "Updating every 600 seconds!"})
return leaderBoardMessageEdit.edit({ embeds: [leaderBoardEmbed]

})
}, 600000);
It doesn't update the embed, it says that no member found on the consol, but people have the hat emoji in their name.
9 Replies
Squid
Squidā€¢3y ago
You're only checking the cached members, so if a member is not cached, you're not even iterating through them to see
d.js docs
d.js docsā€¢3y ago
method GuildMemberManager#fetch() Fetches member(s) from Discord, even if they're offline.
Squid
Squidā€¢3y ago
If you want to access all members, you'll need to use this function (which requires the 'GUILD_MEMBERS' intent)
Frosty
FrostyOPā€¢3y ago
But am i not caching all correctServer members @squiddleton
Squid
Squidā€¢3y ago
You're filtering through the members that are already cached, but the cache isn't automatically full of every member in the guild
Frosty
FrostyOPā€¢3y ago
let allMembers = correctServer.members.fetch()
let membersHat = await allMembers.filter(
(member) =>
member.nickname && member.nickname.toLowerCase().includes("šŸŽ©") ||
member.username && member.username.toLowerCase().includes("šŸŽ©")
);
let allMembers = correctServer.members.fetch()
let membersHat = await allMembers.filter(
(member) =>
member.nickname && member.nickname.toLowerCase().includes("šŸŽ©") ||
member.username && member.username.toLowerCase().includes("šŸŽ©")
);
so somthing like dis? @squiddleton
Squid
Squidā€¢3y ago
The fetch returns a promise, not the filter So you need to move your await
Frosty
FrostyOPā€¢3y ago
So how could i do that?
Squid
Squidā€¢3y ago
Move the await so that it resolves the promise returned by the .fetch() Just ctrl+X and paste it one line up
Want results from more Discord servers?
Add your server