TypeError [INVALID_TYPE]:提供的覆盖不是权限覆盖的数组或集合我遇到此错误

时间:2020-11-03 03:59:57

标签: node.js

我正在尝试使用discord.js锁定node.js中的频道,但如果您能帮助我,我将不胜感激

主要代码:

const Discord = require('discord.js');
const client = new Discord.Client();
 
const prefix = '-';
 
const fs = require('fs');
 
client.commands = new Discord.Collection();
 
const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
for(const file of commandFiles){
    const command = require(`./commands/${file}`);
 
    client.commands.set(command.name, command);
}
client.once('ready', () => {
    console.log('yes its online');
});

client.on('message', async message=>{
    let blacklisted = ['scam','SCAMMER','s*am','*cam','sc*m','sca*'];
    let foundInText = false;
    for(i in blacklisted){
        if(message.content.toLowerCase().includes(blacklisted[i].toLowerCase())) foundInText = true;
    }
    if(foundInText){
        message.delete();
        const hello = message.mentions.users.first();
        message.channel.send("Sorry buddy that's a blacklisted word.")
    }
});

client.on('ready',() => {
    try{
        let serverIn = client.guilds.size;
        console.log(client.user.tag +'has logged in!');
        function pickStatus(){
            let status = ["Real's community","Legit giveaways https://discord.gg/HVT8MMk"];
            let Status = Math.floor(Math.random()*status.length)
            client.user.setActivity(status[Status]),{
                type:"WATCHING"
            }
        };
        setInterval(pickStatus, 8000)
    } catch (err){
        console.log(err)
    }
    
});
client.on('message', message =>{
    if(!message.content.startsWith(prefix) || message.author.bot) return;
 
    const args = message.content.slice(prefix.length).split(/ +/);
    const command = args.shift().toLowerCase();
 
    if(command === 'ping'){
       message.channel.send('pong!')
    }
     if (command === "ban"){
        if(message.member.hasPermission('BAN_MEMBERS')){
            const userBan = message.mentions.users.first();

            if(userBan){
                   var member = message.guild.member(userBan);

                    if(member) {
                           member.ban({
                    reason: 'you broke rules buddy.'
                }).then(() => {
                    message.reply(`${userBan.tag} was banned from the server.`)
                })

            }          else{
                         message.reply('that user is not in the server.');
            }
        }             else {
                            message.reply('you need to state a user to ban')
        }
                       
                     
     
                      
                        
                      

    
}else{
    message.reply("Sorry man but you don't have the power to wield the BAN HAMMER!")
}    
   }
   if(command=== "lock"){
          client.commands.get('lock').execute(message, args);
   }
   
});
 
 




client.login('NzU4MTg0NzcyODY5ODE2MzU4.X2rQmA.LvWgbvHyD4BxUFAvrDe_wtz2REo');

我的lock.js代码

const Discord = require('discord.js');
module.exports = {

    name: 'lock',
    description: "locks things",
   async execute(message, args){
 
     if(!message.member.hasPermission('MANAGE_CHANNELS')) return message.channel.send("Sorry you dont have the perms for this")

     if(!args[0]) return message.channel.send("You did not specify a channel")
     if(!message.mentions.channels.first()) return message.channel.send("You did not specify a valid channel")
     const role = message.guild.roles.cache.get('755778598794821712')
     if(!role) return message.channel.send("Could not find role")
     await message.mentions.channels.forEach(async channel =>{
        if(channel.name.startsWith('L')) return message.channel.send(`<#${channel.id}> is already locked!`)
        await channel.setName(`L${channel.name}`);
        try{
          await channel.overwritePermissions(role,[
          {
          deny: ['SEND_MESSAGES', 'ADD_REACTIONS'],
          },
        ]); 
          message.channel.send(`<#${channel.id}> has been locked!`);
        } catch(err){
            console.log(err)
            message.channel.send("Something went wrong not sure why error id:$312543_CACh_ERR")
        }
        });
    }
}

如果有人解决了我的问题,并在终端中显示此错误,我将不胜感激:

TypeError [INVALID_TYPE]: Supplied overwrites is not an Array or Collection of Permission Overwrites

我正在使用discord.js v12顺便说一句,看到了一些解决方案,但没有什么使代码能够正常工作,除了锁定通道:(

0 个答案:

没有答案