I wonder if you can help (I search it and nothing...) I am learning how to work with discord.js node and I want to change my user nickname (not the username itself)
You can use the GuildMember#setNickname function like this:
var nick = message.content.split(" ").slice(1).join(" ");
message.member.setNickname(nick);
like @Zaidhaan said, heres a little snippet that only trys to set the nickname if it has the perms
if (message.guild.members.get(bot.user.id).hasPermission("MANAGE_NICKNAMES") && message.guild.members.get(bot.user.id).hasPermission("CHANGE_NICKNAME")) {
message.guild.members.get(bot.user.id).setNickname("Nickname Here");
} else {
message.channel.sendMessage("I dont have the permissons to change my nickname in this server.");
}
since your getting the user via message.guild.members.get()
it requires the perms to edit nicknames on the server
Try to use this: Docs Guild#Me
var newNickname = "Nickname !"
message.guild.me.setNickname(newNickname);
Note: bot should get MANAGE_NICKNAMES
It should work if you use this
message.guild.members.get("Random ID or something").setNickname("RandomName")
What it looks like is that you are trying to give your bot a nickname To change the bot's nickname use this:
const Discord = require('discord.js');
const client = new Discord.Client();
client.on('ready', () => {
console.log('I am ready!');
});
client.on('message', message => {
if (message.content.toLowerCase().startsWith('changeNick')) {
var newNickname = message.content.replace("changeNick ", "");
message.guild.me.setNickname(newNickname);
}
});
If you want to change a users nickname you should use this:
const Discord = require('discord.js');
const client = new Discord.Client();
client.on('ready', () => {
console.log('I am ready!');
});
client.on('message', message => {
let args = message.content.split(" ");
if(message.content.toLowerCase().startsWith("changeNick")){
if(!message.mentions.users.first()) return message.channel.send("You didn't specify a user!");
const user = message.mentions.members.first();
const username = message.guild.members.cache.find(userI => userI.id == user);
var newNickname = message.content.replace("changeNick "+args[1], "");
username.setNickname(newNickname);
}
});
should you use discord.js GuildMember.setNickname function instead of Client.setNickname ()
client.on ('message', async message => {
var nickname = message.content.split (" ").slice (1).join (" ");
if (message.content.startsWith ('setNickname')) {
message.member.setNickname (nickname);
}
});