TypeError: Cannot read properties of undefined (reading 'cache') discord.js V13 command interaction

TypeError: Cannot read properties of undefined (reading 'cache') discord.js V13 command interaction

当执行的命令是取消静音命令时出现此错误 我的处理程序是一个斜杠命令

when i set the the member as member type in options its work fine but i want it with ID if anyone have a solutions and thx

        if(target.roles.cache.has(muterole)) {
                        ^

TypeError: Cannot read properties of undefined (reading 'cache')

这是命令:

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


module.exports = {
    name: "unmute",
    description: "Unmute a Member",
    permission: "MANAGE_MESSAGES",
    options: [
        {
            name: "member",
            description: "Member ID",
            required: true,
            type: "STRING"
        },
        {
            name: "reason",
            description: "provide unmute reason",
            required: true,
            type: "STRING"
        }
    ],
    /**
     * 
     * @param {CommandInteraction} interaction 
     */
    async execute(interaction) {
        const { guild, channel, member, options } = interaction;

        const target = options.getString("member");
        const reason = options.getString("reason");
        const logchannel = guild.channels.cache.get("877754209016086588");
        const muterole = guild.roles.cache.get("944200095040167946");
        console.log(target);
        const logembed = new MessageEmbed()
        .setColor("AQUA")
        .setAuthor({ name: `${member.user.tag}`, iconURL: `${member.user.avatarURL({ dynamic: true, size: 512 })}` })
        .setDescription(`
${target} got unmuted 
        by : ${member}
        reason : ${reason}
        `)
        .setTimestamp();
        const response = new MessageEmbed()
        .setDescription(`
${target} unmuted
        `);
        if(target.roles.cache.has(muterole)) {
            await target.roles.remove(muterole);
            await interaction.reply({embeds: [response], ephemeral: true});
            await logchannel.send({
                    content: `${member}`,
                    embeds: [logembed]
            });
        } else {
            await interaction.reply({content: `${target} is not muted`, ephemeral: true});
        }
    }
}
  • USER 类型支持 Snowflake ID用户提及 & 会员提及 .
  • 您可以添加 type: "USER" 并使用
const member = interaction.options.getMember("target"); // for a GuildMember
const user = interaction.options.getUser("target"); // for a User
  • 再次支持用户 ID 和提及。
  • 使用字符串获取 member/user 效率不高,因为如果提供的 ID 无效,机器人 returns null 可能会导致崩溃。