unable to access cache for member.roles

for some reason the if(!member.roles.cache.find('')) is coming back as undefined. What did I do wrong?
const reactions = await message.reactions.cache.get("❤️");
const members = await reactions.users.fetch();
let updatedMembers = 0;

await members.forEach((member) => {
if(!member.roles.cache.find("1171954559611047986" && member.kickable === 'true')){
member.roles.add("1171954559611047986");
console.log(`Assigned the rule verified role to ${member.user.name}`);
updatedMembers++;
} else {
console.log(`${member.user.name} is already verified or no longer in the server.`);
}
});
const reactions = await message.reactions.cache.get("❤️");
const members = await reactions.users.fetch();
let updatedMembers = 0;

await members.forEach((member) => {
if(!member.roles.cache.find("1171954559611047986" && member.kickable === 'true')){
member.roles.add("1171954559611047986");
console.log(`Assigned the rule verified role to ${member.user.name}`);
updatedMembers++;
} else {
console.log(`${member.user.name} is already verified or no longer in the server.`);
}
});
6 Replies
d.js toolkit
d.js toolkit12mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
duck
duck12mo ago
given that <Collection>.find() accepts a test function, not a boolean, it's likely that code isn't even executing furthermore <ReactionUserManager>.fetch() would resolve with a collection of Users, not GuildMembers, so you'll have trouble accessing their roles from there
Snapper
Snapper12mo ago
oooh okay. I'll take a look into it for myself and come back if I still can't figure it out. Thank you for the hint!
Mark
Mark12mo ago
get or has would be the better methods to use
Unknown User
Unknown User12mo ago
Message Not Public
Sign In & Join Server To View
Snapper
Snapper12mo ago
thank you for all the suggestions 🙂 I'm still struggling a little bit with this one.
const reactions = await message.reactions.cache.get(":heart:");
const users = await reactions.users.fetch();
const members = await interaction.guild.members.fetch();
let updatedMembers = 0;

await users.forEach((user) => {
let guildMemberObject = members.find(member => member.id === user.id);
console.log(guildMemberObject);
const reactions = await message.reactions.cache.get(":heart:");
const users = await reactions.users.fetch();
const members = await interaction.guild.members.fetch();
let updatedMembers = 0;

await users.forEach((user) => {
let guildMemberObject = members.find(member => member.id === user.id);
console.log(guildMemberObject);
so, I tried .get() and .has() but it looks like neither of them are a function of the collection that gets created when I fetch() the server members. I thought I might be able to match them by id to the user, but that's also failing I was reading up on it and it looks like fetching over 100 guild members will leave the fetch command hanging. I'm still not super familiar with data structures since I'm home taught. Is there a way I could fetch half the members in the collection and then fetch the other half so that I don't hit a timeout during the fetch()? NVM I figured it out. I just made something really scuffed but it works x'D
Want results from more Discord servers?
Add your server