Home > other >  TypeError: Cannot read properties of undefined (reading 'getUser')
TypeError: Cannot read properties of undefined (reading 'getUser')

Time:01-25

My Code

module.exports = {
    data: new SlashCommandBuilder()
        .setName('remove')
        .setDescription('Removes a user to the ticket')
        .addSubcommand(subcommand =>
            subcommand
                .setName('user')
                .setDescription('Remove taged User')
                .addUserOption(option => option.setName('user').setDescription('The user'))), 
    async execute(interaction, client) {

        const channel = interaction.channel;
        const user = interaction.subcommand.getUser('user');
        
        channel.permissionOverwrites.edit(user, { 
            'ViewChannel': false,
             'SendMessages': false
        });
        await interaction.channel.reply({ content: `${user} Has been removed from the ticket!`});
    },
};

Error: TypeError: Cannot read properties of undefined (reading 'getUser')

Trying to remove a user from the channel when this command is ran

CodePudding user response:

interaction.subcommand does not exist. You probably meant to use interaction.options, which is a CommandInteractionOptionResolver

const user = interaction.options.getUser('user')

The discord.js guide explains how to parse options from a command.

  • Related