我正在为我的服务器制作一个 discord bot,但我的取消静音命令遇到了一些问题,当我尝试运行 cannot get property 'roles' of undefined
时出现错误 user.roles.remove(mutedRole)
。任何帮助表示赞赏,我的代码粘贴在下面。
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`));