Finding members with specific emoji in their name problem.

I have this kind of code i made:
callback: async ({ message, args }) => {

const emojiInName = ["🎩"]
let members = await message.guild.members.fetch();
for(let member of members)
if(emojiInName.some(emoji => member.nickname.includes(emoji))){
message.channel.send({ content: `${member} has the emoji in name`})
} else return;

},
callback: async ({ message, args }) => {

const emojiInName = ["🎩"]
let members = await message.guild.members.fetch();
for(let member of members)
if(emojiInName.some(emoji => member.nickname.includes(emoji))){
message.channel.send({ content: `${member} has the emoji in name`})
} else return;

},
But i get this: TypeError: Cannot read properties of undefined (reading 'includes')
10 Replies
Squid
Squid•3y ago
It would be null, not undefined You should iterate over members.values() instead of members, or else each member is a [string, GuildMember] array instead of just a GuildMember object (but using displayName is still probably the way to go if you're not doing optional chaining)
Frosty
FrostyOP•3y ago
callback: async ({ message, args }) => {

const emojiInName = ["🎩"]
let members = await message.guild.members.fetch();
for(let member of members) {
if(emojiInName.some(emoji => members.values().displayName.includes(emoji))){
message.channel.send({ content: `${member} has the emoji in name`})
}
}

},
callback: async ({ message, args }) => {

const emojiInName = ["🎩"]
let members = await message.guild.members.fetch();
for(let member of members) {
if(emojiInName.some(emoji => members.values().displayName.includes(emoji))){
message.channel.send({ content: `${member} has the emoji in name`})
}
}

},
So something like thsi?
Jaworek
Jaworek•3y ago
members.values() is iterable and for sure it doesn't have displayName poperty
Frosty
FrostyOP•3y ago
But if i do it like this?
let members = await message.guild.members.fetch();

for (let member of members) {

if (member.displayName.includes("🎩")) {
console.log("someone has the thing");
}

}
let members = await message.guild.members.fetch();

for (let member of members) {

if (member.displayName.includes("🎩")) {
console.log("someone has the thing");
}

}
Jaworek
Jaworek•3y ago
in this case member is array of key and value
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Frosty
FrostyOP•3y ago
I got it working.
Jaworek
Jaworek•3y ago
meguFace
Frosty
FrostyOP•3y ago
let membersHat = await message.guild.members.cache.filter(
(member) =>
member.nickname && member.nickname.toLowerCase().includes("🎩")
);
if (membersHat.size === 0) console.log("No members found");

let countHat = 0;
membersHat.forEach((member) => {
countHat = countHat + 1;
});
let membersHat = await message.guild.members.cache.filter(
(member) =>
member.nickname && member.nickname.toLowerCase().includes("🎩")
);
if (membersHat.size === 0) console.log("No members found");

let countHat = 0;
membersHat.forEach((member) => {
countHat = countHat + 1;
});
used something like this. Ignore the count thing.
Jaworek
Jaworek•3y ago
its filter, you can use forEach instead
Want results from more Discord servers?
Add your server