因此,此命令在管理员键入$mute @user1 @user2 @user3
时使所有被标记的人静音,如果第一次在该服务器上使用该命令,它将创建一个新角色“ ModrajMute”,但是我遇到的问题是创建角色时,它不会锁定该角色的所有通道(错误:无法读取未定义的属性“ id””。
如果有人知道如何为我解决该问题,谢谢
我的代码:
client.on('message', async message => {
if (message.content.startsWith(prefix + "mute")) {
if (!message.member.hasPermission('ADMINISTRATOR')) return message.channel.send('You do not have that permission! :x:').then(message.react(':x:'))
let muteRole = message.guild.roles.cache.find(role => role.name == "ModrajMute")
const channels = message.guild.channels.cache.filter(ch => ch.type !== "category")
if(!muteRole) {
const MuteRole = await message.guild.roles.create({
data:{
name: `ModrajMute`,
color: "DEFAULT",
permissions: ['READ_MESSAGE_HISTORY']
}}).then(message.guild.channels.cache.forEach(ch => {
if (ch.type == "text")
ch.overwritePermissions([
{
id: muteRole.id,
deny: ['SEND_MESSAGES'],
},
], 'Needed to change permissions');
}) )
message.channel.send("Succesfully created the `ModrajMute` role, please write the command again and mute the person.")
} else if(!message.mentions.members.first()) return message.channel.send("Please mention a user or users that you want to mute.")
if(message.mentions.members.first()) {
message.mentions.members.forEach(member => member.roles.add(muteRole))
message.channel.send("Succesfully muted the user/users.")
}
}})
答案 0 :(得分:1)
const MuteRole
应该是const muteRole
。因为Cannot read property 'id' of undefined
未定义,所以您得到muteRole
。