无法读取未定义的属性“执行”

时间:2020-07-22 12:35:03

标签: discord.js

我有一个脚本,如果命令正确,它将运行另一个脚本,但它会返回 that

这是代码 获取文件的代码

const fs = require("fs");
const { settings } = require("cluster");
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);
}

命令代码

    if (command == "setup"){
    Client.commands.get("setup").execute(message,args,prefix);
}

设置命令

const Discord = require("discord.js")
const db = require("quick.db")

module.exports = {
name: "Setup",
desc: "Main command to setup the bot",
execute(message, args, prefix){
    const ma = message.author.id

    const embed = new Discord.MessageEmbed()
    .setTitle("Setup bot - " + message.guild.name)
    .setDescription("Here you can setup the bot to do the main things")
    .setColor("#2163D7")
    .addFields(
        { name: '`!moderation`', value: '**Activate moderation features**'},
    )
    .setFooter("Do " + "`" + prefix + "`" + "setup before the command")
    message.channel.send(embed);
   if(message.member.permissions.has("ADMINISTRATOR")){
      message.channel.awaitMessages(ma, { max: 5, }).then(setup => {
        if(args[1] === "moderation"){
            db.set(`setup_moderations_${message.guild}`, true)
          }
      });


   }
}
}

命令的组织方式

here

感谢您的帮助

1 个答案:

答案 0 :(得分:1)

在我看来,问题可能出在字体大小写方面。

您在模块中定义了name: 'Setup'(大写的“ S”)。 但是,您尝试通过键Client.commands.get("setup")(小写的“ s”)访问值,因此该集合没有这样的标识符