1

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

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.