I'm making a discord bot for my server and I have run into some issues with my unmute command, I'm getting the error cannot get property 'roles' of undefined
when I'm trying to run user.roles.remove(mutedRole)
. Any help is appreciated, my code is pasted below.
let user = message.mentions.members.first() || message.guild.members.cache.get(args[0]);
if (!user) return message.channel.send(new Discord.MessageEmbed().setColor(db.get(`${message.guild.id}.color`)).setTimestamp()
.setTitle(`Please specify a user to unmute`));
let mutedRole = message.guild.roles.cache.find(mR => mR.name === "Muted");
if(!mutedRole) mutedRole = await message.guild.roles.create({data:{name: "Muted",color: "#000000",permissions: []}});
message.guild.channels.cache.forEach(async (channel) => {
await channel.updateOverwrite(mutedRole, {
SEND_MESSAGES: false,
SPEAK: false,
VIDEO: false,
ADD_REACTIONS: false,
SEND_TTS_MESSAGES: false,
ATTACH_FILES: false
}).catch()
});
if(!user.roles.cache.find(mR => mR.name === "Muted")) return message.channel.send(new Discord.MessageEmbed().setColor(db.get(`${message.guild.id}.color`)).setTimestamp()
.setTitle(``${user.user.username}` is not muted`));
//Im getting the error here
user.roles.remove(mutedRole);
message.channel.send(new Discord.MessageEmbed().setColor(db.get(`${message.guild.id}.color`)).setTimestamp()
.setTitle(``${user.user.username}` has been unmuted`));
question from:
https://stackoverflow.com/questions/66056071/cannot-read-property-roles-of-undefined-discord-js-unmute-command 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…