我试图创建一个锁定命令,用户可以在其中选择要覆盖的权限。但是,只有在产生以下错误时删除第3条和第4条if
语句(检查现有权限是否被覆盖)时,此方法才有效:RangeError [BITFIELD_INVALID]: Invalid bitfield flag or number.
是否可以解决此问题?
const channel = bot.channels.cache.get(args[0]);
if(!channel) {
return message.reply('Please provide a channel id!');
}
if(!args[1]) {
return message.reply('Please set the lock type!');
}
if (!channel.permissionsFor(message.guild.roles.everyone).has('VIEW_CHANNEL')) {
const errorEmbed = new Discord.MessageEmbed()
.setDescription(`❌ \`VIEW_CHANNEL\` for \`${channel.name}\` is already disabled.`)
.setColor('RED');
return message.channel.send(errorEmbed);
}
if (!channel.permissionsFor(message.guild.roles.everyone).has('READ_MESSAGES')) {
const errorEmbed = new Discord.MessageEmbed()
.setDescription(`❌ \`READ_MESSAGES\` for \`${channel.name}\` is already disabled.`)
.setColor('RED');
return message.channel.send(errorEmbed);
}
else if (args[1] === 'view' || args[1] === 'read') {
channel.updateOverwrite(message.channel.guild.roles.everyone, { VIEW_CHANNEL: false }).then(() => {
const msgEmbed = new Discord.MessageEmbed()
.setDescription(`✅ The channel\`${message.channel.name}\` has been locked.`)
.setColor('GREEN');
message.channel.send(msgEmbed);
}).catch((error) => {
console.log(error);
const errorEmbed = new Discord.MessageEmbed()
.setDescription(`❌ Unable to lock \`${channel.name}\`.`)
.setColor('RED');
message.channel.send(errorEmbed);
});
}
else if (args[1] === 'send') {
channel.updateOverwrite(message.channel.guild.roles.everyone, { SEND_MESSAGES: false }).then(() => {
const msgEmbed = new Discord.MessageEmbed()
.setDescription(`✅ The channel\`${channel.name}\` has been locked.`)
.setColor('GREEN');
message.channel.send(msgEmbed);
}).catch((error) => {
console.log(error);
const errorEmbed = new Discord.MessageEmbed()
.setDescription(`❌ Unable to lock \`${channel.name}\`.`)
.setColor('RED');
message.channel.send(errorEmbed);
});
}
答案 0 :(得分:0)
我认为这是因为您使用READ_MESSAGES
而不是在各处使用VIEW_CHANNEL
(这是相同的,并且我认为READ_MESSAGES
已从Discord.js v12中删除)。