Permission Error Nickname Change Command discord js

Viewed 24

There is no permission error when using code a, but there is a permission error whenever using code b. Is there a solution?

    module.exports = {
        name: "NICK",
        async execute(message, args, client) {
            //A: const member = message.mentions.members.first();

            //B: const member = await message.guild.members.cache.get(message.author.id)


    console.log(message.author.id)
    if (!member) return message.reply("target error");
    
    const arguments = args.shift(1)
    
    if (!arguments) return message.reply("name error");
    
    try {
        const arguments = args.shift(1)
      member.setNickname(arguments);
    }catch (error) {
            console.error(error);
            
        }
    },
};

I currently have these intents

const { Client, GatewayIntentBits, Collection, MembershipScreeningFieldType, ClientUser, User, time, GuildChannel, GuildManager, MessageManager, GuildMemberManager, GuildBanManager, GuildBan, GuildStickerManager, PermissionsBitField, PermissionOverwriteManager, MessageFlagsBitField, GuildMemberRoleManager, gu } = require('discord.js');
const { record } = require('../config.json');
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMessageReactions, GatewayIntentBits.GuildVoiceStates, GatewayIntentBits.DirectMessages, GatewayIntentBits.MessageContent, GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers, GatewayIntentBits.GuildBans] });
1 Answers

Checking code B I could say a few things:

  1. You don't need to await a cache.get() call;
  2. If you are the owner of the guild, then the bot needs to have a role above your highest role to change your nickname.
Related