So today I've tried to create command in discord bot that can rename user which typed the command to something else. However no matter what I do this code allways returns error Missing Permissions.
const {Client, GatewayIntentBits, EmbedBuilder, SlashCommandBuilder, Guild} = require('discord.js');
const client = new Client(
{
intents:
[
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.MessageContent,
]
}
);
client.on("ready", () =>
{
console.log("Bot is ready!");
const nicknameCH = new SlashCommandBuilder()
.setName('changenick')
.setDescription('Changing nickname')
.addStringOption((option) =>
{
return option
.setName("newnick")
.setRequired(true)
})
client.application.commands.create(nicknameCH);
});
client.on('interactionCreate', (interaction) =>
{
if(!interaction.isChatInputCommand()) return;
if(interaction.commandName === 'changenick')
{
const stringOption = interaction.options.getString("newnick").toString();
const thisUser = interaction.guild.members.cache.get(interaction.user.id);
thisUser.setNickname(stringOption);
interaction.reply('Changing to: ' + stringOption);
}
});
client.login(TOKEN)
I've set bot role to highest place in roles tab on discord server settings and given him Admin permission, reinvited him.
I'm expecting to change user nickname no matter if he has permissions to do that or not via bot
Most likely you want to change a nickname of the server owner (I guess its you). Noone has permissions to change a nick of the owner. (No matter how high role the bot has). Use that command on some of your friend or your alt account.