Javascript Discord.js V12禁用所有标记的人,创建一个角色,同时锁定所有频道

Javascript Discord.js V12禁用所有标记的人,创建一个角色,同时锁定所有频道,javascript,discord.js,Javascript,Discord.js,因此,这个命令,当管理员键入$mute@user1@user2@user3时,它会使每个被标记的人都静音,而且如果是第一次在该服务器上使用该命令,它会创建一个新角色“ModrajMute”,但我遇到的问题是,当它创建该角色时,它不会锁定该角色的所有频道(错误:无法读取未定义的属性“id”)。 如果有人知道如何为我解决这个问题,谢谢 我的代码: client.on('message', async message => { if (message.content.startsWith

因此,这个命令,当管理员键入
$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.")
   }
    }})

const MuteRole
应该是
const MuteRole
。您得到的
无法读取未定义的属性“id”
,因为
MuteRole
未定义。

嘿,我有点晚了,我已经修复了它,但是现在我得到了一个“ReferenceError:在初始化之前无法访问'MuteRole'“错误。很抱歉,我也迟到了。这意味着您正在尝试在创建
互斥角色之前访问它。”。