最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Discord.JS get member from user ID - Stack Overflow

programmeradmin0浏览0评论

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.

Share Improve this question asked Jan 31, 2021 at 14:30 S.W.L. de BruinS.W.L. de Bruin 131 gold badge1 silver badge3 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

Instead 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.

发布评论

评论列表(0)

  1. 暂无评论