NodeJS TypeError:无法读取未定义的属性(阅读“getUser”)

pb3skfrl  于 2023-01-25  发布在  Node.js
关注(0)|答案(1)|浏览(157)

我的代码

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!`});
    },
};

错误:类型错误:无法读取未定义的属性(阅读“getUser”)
运行此命令时尝试从频道中删除用户

mzsu5hc0

mzsu5hc01#

interaction.subcommand不存在。您可能希望使用interaction.options,它是CommandInteractionOptionResolver

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

discord.js指南解释了如何解析命令中的选项。

相关问题