Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

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

I get this error when the command executed the command is an unmute command and my handler is a slash command

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')

this the command :

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});
        }
    }
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

  • USER type supports Snowflake Ids, User Mentions & Member Mentions.
  • You can add type: "USER" and use
const member = interaction.options.getMember("target"); // for a GuildMember
const user = interaction.options.getUser("target"); // for a User
  • Once again, it supports user IDs and mentions.
  • Using a string for fetching a member/user isn't efficient because if the ID provided is invalid, the bot returns null and might lead to a crash.
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!