message.guild.members.getMember not working

老子叫甜甜 提交于 2021-02-11 14:27:09

问题


I am creating a user info command and DiscordJS keeps saying
TypeError: message.guild.members.get is not a function

The function I'm using is this
let target = message.guild.members.getMember(toFind);

Is there something I need to update with a newer version of DiscordJS? I haven't been able to find anything yet.

Thanks, Jude Wilson


回答1:


The new version of Discord.js is v12, there has been many breaking changes

The function you are probably looking for is:

message.guild.members.fetch(id)

You will probably come across other issues, so check out this guide for moving from v11 to v12: https://discordjs.guide/additional-info/changes-in-v12.html




回答2:


Discord has a new update where you have to use .cache to access discord objects for example: message.guild.members.cache

to get a user:

let user = message.guild.members.cache.fetch("user id");
console.log(user.tag)

// if that doesn't work, use the same code but remove .cache


来源:https://stackoverflow.com/questions/60782924/message-guild-members-getmember-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!