Reputation: 35
I'm trying to change a user's nickname in Discord.js v12, yet for some reason I get the error:
TypeError: fn is not a function
Here is my code:
message.guild.members.cache.find(message.author.id).setNickname(username)
The message
is just a Message
object from a .on("message")
.
Upvotes: 2
Views: 192
Reputation: 23189
Unlike .get()
, .find()
accepts a function, so you can use it like this:
message.guild.members.cache
.find(member => member.id === message.author.id)
.setNickname()
You could also use .get()
:
message.guild.members.cache
.get(message.author.id)
.setNickname()
Or even better, use .fetch()
:
message.guild.members.fetch(message.author.id)
.then(member => member.setNickname())
Or, you can get the member from the message itself using the member
property that represents the author of the message as a guild member:
message.member.setNickName()
Upvotes: 3