Change user nickname
Good morning. I want to change the nickname of the user whose user id is entered in the command option, except I did some research and I found a line of code but it does not work, an idea ?
Error :
20 Replies
• What's your exact discord.js
npm list discord.js
and node node -v
version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.I think you wanna di guild.members.cache.get(), but not all members are cached so you wanna fetch instead and resolve the promise it returns
I'm not quite sure I understand
What do you not understand?
I'm not really sure to understand what I'm going to have to do to change the user's name thanks to his ID, I'm going to have to use a
.cache()
?You would do that if you were sure that member is cached, but I'd recommend to fetch instead as the member might not be cached
Can I retrieve it using its ID?
What I want to do is that I have store the ID in a database with the new username and other information, and I would like to suddenly retrieve the ID and the name store then change the nickname of the user which corresponds to the ID retrieved from the database by the nickname also retrieved from the database. But I don't really see how to do it because it doesn't seem like you can do
fetch()
on an ID, and if it's not in the cache, I don't really see a way out...Yes, you can, guild.members.fetch("id")
And I just need to end with
.setNickname("nickname")
?fetch() returns a promise so you'd need to resolve it first though
And how do I use it and resolve it?
A
(await message.guild.members.fetch(val[0].User)).user
should allow me to retrieve the user?1. If you are using slash commands, just use a user option
2. Use
<Guild>.members.edit(id, { nick })
This way of proceeding seems much simpler.
Didn't know about that, noted for the future, thank you Myth
A question,
DiscordAPIError[50013]: Missing Permissions
this error occurs, if the bot has the Administrator
permissions it must still have the Change a member's nickname
permissions while it is an administrator?- Bots cannot moderate (kick/ban/nickname/...) a target with a higher or equally high highest role or the guild owner.
- Bots cannot modify (edit/add/remove) roles that are higher or equally high compared to the bot's highest role.
- The
Administrator
permission does not skip these checks.Oh I didn't know that he can't change the nickname of the server owner, thank you, that's a thing to know indeed ^^'
Of course