无法读取未定义的属性“执行" [英] Cannot read property 'execute' of undefined

查看:17
本文介绍了无法读取未定义的属性“执行"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I got a script where if the command is right it will run another script but it returns that

这里是代码获取文件的代码

Here is the code Code to get the files

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)
          }
      });


   }
}
}

以及我的命令是如何组织的

And how my commands are organized

这里

感谢您的帮助

推荐答案

在我看来,问题可能与字体大小写有关.

it seems to me, the issue might be about font-cases.

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

you have name: 'Setup'(uppercase 'S') defined in your module. however you are trying to access the value by key Client.commands.get("setup") (lowercase 's'), so the collection does not have such an identifier

这篇关于无法读取未定义的属性“执行"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆