简体   繁体   English

类型错误:无法读取未定义的属性 'has' // Discord.js

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

So, I was creating a bot for my Discord server.所以,我正在为我的 Discord 服务器创建一个机器人。 And I got this error.我得到了这个错误。 Please remember that I am an amateur :).请记住,我是一个业余爱好者:)。 Thanks in advance, appreciate it^^.在此先感谢,不胜感激^^。

 const config = require('../config.js');
 module.exports = message => {
  let client = message.client;
  if (message.author.bot) return;
  if (!message.content.startsWith(config.prefix)) return;
  let command = message.content.split(' ')[0].slice(config.prefix.length);
 let params = message.content.split(' ').slice(1);
 let cmd;
 if (client.commands.has(command)) {
   cmd = client.commands.get(command);
 } else if (client.aliases.has(command)) {
   cmd = client.commands.get(client.aliases.get(command));
 };
 if (cmd) {
   if(!message.guild) {
     if(cmd.config.guildOnly === true) {
       return;
     };
   };
   if (cmd.config.permLevel) {
     if(cmd.config.permLevel === "BOT_OWNER") {
  if(!config.geliştiriciler.includes(message.author.id)) {
       message.channel.send(`Bu komutu kullanabilmek için \`${cmd.config.permLevel}\` yetkisine sahip olmalısın.`).then(msg => msg.delete({timeout: 3000}));
       return;
  }
     }
       if(!message.member.hasPermission(cmd.config.permLevel)) {
     message.channel.send(`Bu komutu kullanabilmek için \`${cmd.config.permLevel}\` yetkisine sahip olmalısın.`).then(msg => msg.delete({timeout: 3000}));
    return;
     };
   };
   cmd.run(client, message, params);
};
};

At line no 7, please try this在第 7 行,请试试这个

const cmd =
  message.client.commands.get(command) ||
  message.client.commands.find(
    (cmd) => cmd.aliases && cmd.aliases.includes(command) // if you're also using aliases
  );

if (!command) return;

Add some booleans for checking if client.commands/client.aliases is undefined.添加一些布尔值来检查 client.commands/client.aliases 是否未定义。

if (client.commands && client.commands.has(command)) {
      cmd = client.commands.get(command);
    } else if (client.aliases && client.aliases.has(command)) {
      cmd = client.commands.get(client.aliases.get(command));
    };

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

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