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});
}
}
}
USER type supports Snowflake Ids, User Mentions & Member Mentions.type: "USER" and useconst member = interaction.options.getMember("target"); // for a GuildMember
const user = interaction.options.getUser("target"); // for a User
null and might lead to a crash.