Skip to content
Advertisement

TypeError: user.setNickname is not a function

so I have just finished this /setnick command for my Discord Bot, but I am getting the following error.

TypeError: user.setNickname is not a function
    at Object.execute (/Users/Aplex/Downloads/Aplel-Bot/Commands/Moderation/setnick.js:43:24)
    at Object.execute (/Users/Aplex/Downloads/Aplel-Bot/Events/Interaction/interactionCreate.js:24:15)
    at Client.<anonymous> (/Users/Aplex/Downloads/Aplel-Bot/Structures/Handlers/Events.js:17:50)
    at Client.emit (node:events:402:35)
    at InteractionCreateAction.handle (/Users/Aplex/Downloads/Aplel-Bot/node_modules/discord.js/src/client/actions/InteractionCreate.js:74:12)
    at Object.module.exports [as INTERACTION_CREATE] (/Users/Aplex/Downloads/Aplel-Bot/node_modules/discord.js/src/client/websocket/handlers/INTERACTION_CREATE.js:4:36)
    at WebSocketManager.handlePacket (/Users/Aplex/Downloads/Aplel-Bot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:351:31)
    at WebSocketShard.onPacket (/Users/Aplex/Downloads/Aplel-Bot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:444:22)
    at WebSocketShard.onMessage (/Users/Aplex/Downloads/Aplel-Bot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:301:10)
    at WebSocket.onMessage (/Users/Aplex/Downloads/Aplel-Bot/node_modules/ws/lib/event-target.js:199:18)

I have tried looking for solutions on google and here on StackOverflow but I couldn’t find any regarding my problem. Does anyone know what the fix for this is?

Here is the /setnick command file:

const { Client, Interaction, MessageEmbed } = require("discord.js");

module.exports = {
    name: "setnick",
    description: "Sets nicname to a user.",
    options: [
        {
            name: "user",
            description: "User to change nickname",
            type: 6,
            required: true
        },
        {
            name: "nickname",
            description: "New nickname",
            type: 3,
            required: true,
        },
    ],
    /**
     * 
     * @param {Interaction} interaction 
     * @param {Client} client 
     */
    async execute(interaction, client) {
        try {
            const { options } = interaction;
            const args = options._hoistedOptions;

            const user = args.find(x => x.name == "user");
            const nickname = args.find(x => x.name == "nickname");

            const embed = new MessageEmbed()
            .setColor("RED")

            if(!user.member.manageable) {
                embed.setDescription(`:x: I can't change ${user.member.toString()}'s Nickname`)
                return interaction.reply({embeds: })
            }

            const oldNick = user.member.nickname ? user.member.nickname : user.member.user.username;

            await user.setNickname(nickname.value);

            embed.setDescription(`:white_check_mark: ${user.member.toString()}'s nickname changed!`).setFooter(`From ${oldNick} to ${nickname.value}`);

            await interaction.reply({embeds: });
        } catch (err) {
            console.log("Something went wrong => ", err);
        }
    },
};

Advertisement

Answer

Should be

await user.member.setNickname(nickname.value)
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement