Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

184
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda