在 discord.js 中创建别名系统时出现错误

I'm getting error while making an alias system in discord.js

我正在为我的 discord 机器人制作别名系统,我想说:“如果用户输入了错误的命令名称或别名,那么 return:无效 command/alias",但出现错误:

C:\Users\Pooyan\Desktop\PDM Bot Main\events\guild\message.js:16
                    if(!cmd || client.commands.find(a => !a.aliases && !a.aliases.includes(cmd))) return message.channel.send('Invalid command');
                                                                                  ^

TypeError: Cannot read properties of undefined (reading 'includes')
    at C:\Users\Pooyan\Desktop\PDM Bot Main\events\guild\message.js:16:83

我的代码:

module.exports = async (message, client, Discord) => {
    const prefix = process.env.PREFIX;

    if(!message.content.startsWith(prefix) || message.author.bot) return;

    const args = message.content.slice(prefix.length).split(/ +/);
    const cmd = args.shift().toLowerCase();

    const command = client.commands.get(cmd) || 
                    client.commands.find(a => a.aliases && a.aliases.includes(cmd));
                    if(!cmd || client.commands.find(a => !a.aliases && !a.aliases.includes(cmd))) return message.channel.send('Invalid command');
}

我正在使用 discord.js v13 和 Node.js v16.14.2

删除查找方法中的第一个 !,它将修复错误

我自己找到了解决方案, 我需要做的就是:

 if(!command) return message.channel.send('Invalid Command/alias');

在那两行之后, 表示如果命令名称不正确,或者别名不正确,return“无效Command/alias”