首页 > 解决方案 > Visual Studio 代码终端 - 类型错误:无法读取未定义的属性“执行”

问题描述

嗨,我在使用Visual Studio 代码时遇到问题,终端显示TypeError: Cannot read property 'execute' of undefined谢谢

有人可以帮忙 - [1]:https ://i.stack.imgur.com/Ax2Ra.png

for(const file of commandFiles){
    const command = require(`./commands/${file}`);

    client.commands.set(command.name, command);
}

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

标签: visual-studio-2010terminalsyntax-errorexecute

解决方案


改变这一行:

if (command === 'ping'){
    client.commands.get('ping').execute(message, args);
}

到这一行:

if (command == 'ping'){
    client.commands.get('ping').execute(message, args);
}

推荐阅读