问题
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 thislet 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