I'm pretty new to Discord.js and Stackoverflow. So I don't know exactly how to do this.
I do know that this question has been asked many times, sadly any I've found haven't worked.
I'm trying to assign roles to members on their birthday. I want to do this with a crontab. Now I have their user ID's but sadly when I request the member with this code.
let guild = client.guilds.cache.get('Guild ID');
let member = guild.members.cache.get('User ID');
console.log(member);
I just get an undefined
message. Now I know that the user ID is correct. I just don't know why I get the undefined
message.
I'm pretty new to Discord.js and Stackoverflow. So I don't know exactly how to do this.
I do know that this question has been asked many times, sadly any I've found haven't worked.
I'm trying to assign roles to members on their birthday. I want to do this with a crontab. Now I have their user ID's but sadly when I request the member with this code.
let guild = client.guilds.cache.get('Guild ID');
let member = guild.members.cache.get('User ID');
console.log(member);
I just get an undefined
message. Now I know that the user ID is correct. I just don't know why I get the undefined
message.
2 Answers
Reset to default 5Instead of using:
let guild = client.guilds.cache.get('Guild ID');
let member = guild.members.cache.get('User ID');
I prefer to use something like:
let person = client.members.cache.get('User ID');
console.log(person);
If you still have problems, you will have to enable the Intents on the Discord Developers Portal
Image:
The cache probably doesn't have the user so you should try this method instead: https://discord.js/#/docs/main/stable/class/GuildMemberManager?scrollTo=fetch.