簡體   English   中英

有沒有辦法檢查頻道覆蓋? (Discord.js v12)

[英]Is there a way to check for channel overwrites? (Discord.js v12)

我正在創建一個用於鎖定頻道的命令,並使用.updateOverwrite()方法來執行此操作。 使用下面的代碼,我試圖檢查通道是否已經將VIEW_CHANNEL設置為 false 並因此響應錯誤消息。 但是,即使頻道已經被鎖定,它仍然會再次“鎖定”它並跳過檢查,這個檢查似乎只在頻道解鎖時被觸發。 是否有其他方法來檢查頻道覆蓋?

    if (message.member.hasPermission('MANAGE_CHANNELS')) {
      if (!message.guild.roles.everyone.permissions.has('VIEW_CHANNEL')) {
        const errorEmbed = new Discord.MessageEmbed()
          .setDescription(`❌ '${message.channel.name}' is already locked.`)
          .setColor('RED');
        message.channel.send(errorEmbed);
      }
      else{
        message.channel.updateOverwrite(message.channel.guild.roles.everyone, { VIEW_CHANNEL: false }).then(() => {
          const msgEmbed = new Discord.MessageEmbed()
            .setDescription(`✅ '${message.channel.name}' has been locked.`)
            .setColor('GREEN');
          message.channel.send(msgEmbed);
        });
      }
    }
    else {
      const warningEmbed = new Discord.MessageEmbed()
        .setDescription('🔒 Sorry, you do not have sufficient permissions to do this.')
        .setColor('YELLOW');
      message.channel.send(warningEmbed);
    }

您需要檢查channel的權限,您當前正在檢查全局角色權限。 這是更新的代碼:

if (message.member.hasPermission('MANAGE_CHANNELS')) {
      if (!message.channel.permissionsFor(message.guild.roles.everyone).has('VIEW_CHANNEL')) {
        const errorEmbed = new Discord.MessageEmbed()
          .setDescription(`❌ '${message.channel.name}' is already locked.`)
          .setColor('RED');
        message.channel.send(errorEmbed);
      }
      else{
        message.channel.updateOverwrite(message.channel.guild.roles.everyone, { VIEW_CHANNEL: false }).then(() => {
          const msgEmbed = new Discord.MessageEmbed()
            .setDescription(`✅ '${message.channel.name}' has been locked.`)
            .setColor('GREEN');
          message.channel.send(msgEmbed);
        });
      }
    }
    else {
      const warningEmbed = new Discord.MessageEmbed()
        .setDescription('🔒 Sorry, you do not have sufficient permissions to do this.')
        .setColor('YELLOW');
      message.channel.send(warningEmbed);
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM