Reputation: 199
So, I made a command which sends you a DM with a button, in this case, a captcha button. After you press the button, it goes into a guild and searches for you inside of it so it can give you a role.
let gn = bot.guilds.cache.get('906210773989203990');
let member = gn.members.cache.find(x => x.id == interaction.user.id);
member.roles.add(role.id);
Whenever I try to console.log member, it returns undefined. (and yes, I have already tried logging interaction.user.id and it works fine.)
Upvotes: 1
Views: 453
Reputation: 9041
The member is not found in the cache, but you can fetch the member
let member = await gn.members.fetch(interaction.user.id)
But simply using interaction.member
is much better
let member = interaction.member
Upvotes: 3
Reputation: 67
I'm not sure, but try to replace your let member = gn.members.cache.find(x => x.id == interaction.user.id);
with let member = gn.members.cache.fetch(interaction.user.id);
Upvotes: -1