简体   繁体   English

Discord.js“类型错误:无法读取未定义的属性‘有’”

[英]Discord.js "TypeError: Cannot read property 'has' of undefined"

I'm doing a bot in discord, I was trying to do a kick command, but every time I execute the command, in the terminal it says "TypeError: Cannot read property 'has' of undefined"我在 discord 中做一个机器人,我试图做一个踢命令,但每次我执行命令时,在终端中都会显示“TypeError:无法读取属性‘有’未定义”

Kick script:踢脚脚本:

module.exports = {
    name: 'kick',
    description: "This command kicks a member",
    execute(message, args){
        if(message.member.permission.has("KICK_MEMBERS")){
            const member = message.mentions.users.first();
            if(member){
                const memberTarger = message.guild.members.cache.get(member.id);
                memberTarger.kick();
                message.channel.send('User has been kicked');
            }else{
                message.channel.send('You couldnt kick this member');
            }
        }
    }
}

Main script:主脚本:

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('Bot is ready');
});

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'){
        client.commands.get('ping').execute(message, args);
    } else if (command === 'clear'){
        client.commands.get('clear').execute(message, args);
    } else if (command === 'kick'){
        client.commands.get('kick').execute(message, args);
    }
});

According to the documentation it's: member.hasPermission('KICK_MEMBERS')根据文档,它是: member.hasPermission('KICK_MEMBERS')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM