我正在制作一个不和谐的机器人,但我在故障排除方面遇到了麻烦.它给了我几个错误,但我不知道它们是什么意思



我正在设置一个不和谐的机器人。 它将是一个具有某些命令的通信机器人。 我的机器人现在无法打开,因为它给了我以下错误代码

E:FLRP Communicationpackage.js:20
bot.command.set(props.help.name, props);
                ^
TypeError: Cannot read property 'set' of undefined
    at jsfile.forEach (E:FLRP Communicationpackage.js:20:17)
    at Array.forEach (<anonymous>)
    at fs.readdir (E:FLRP Communicationpackage.js:17:10)
    at FSReqWrap.oncomplete (fs.js:141:20)

我正在使用教程视频,但我像他一样做了所有事情。 我不知道还能做什么

const Discord = require("discord.js");
const Config = require("./config.json");
const Token = require("./token.json");
const fs = require("fs");
const bot = new Discord.Client({disableEveryone: true});
bot.commands = new Discord.Collection();
fs.readdir("./commands/", (err, files) =>{
  if(err) console.log(err);
  let jsfile = files.filter(f => f.split(".").pop() === "js")
  if(jsfile.length <= 0){
    console.log("could not find command.");
    return;
  }
  jsfile.forEach((f, i) =>{
    let props = require(`./commands/${f}`);
    console.log(`${f} loaded`);
    bot.command.set(props.help.name, props);
  });
});
bot.on("ready", async () =>{
  console.log(`${bot.user.username} is online! Its running on
${bot.guilds.size} servers`);
  bot.user.setActivity("Work in progress", {type: "PLAYING"});
});
bot.on("message", async message =>{
  if(message.author.bot) return;
  if(message.channel.type === "dm") return;
  let prefix = Config.prefix;
  let msgArray = message.content.split(" ");
  let cmd = msgArray[0];
  let args = msgArray.slice(1);
  let cmdFile = bot.commands.get(cmd.slice(prefix.length));
  if(cmdFile) cmdFile.run(bot, message, args);
});
bot.login(Token.token);

我希望机器人首先打开(但它没有(。 在此错误之后可能会出现更多错误,但当时仅显示 1

提前致谢

您正在使用上述bot.commands但随后使用:

bot.command.set(props.help.name, props);

将其更改为:

bot.commands.set(props.help.name, props);

相关内容

最新更新