我正在制作一个不和谐的机器人,但我在故障排除方面遇到了麻烦。它给了我一些错误,但我不知道它们是什么意思
Im making a discord bot but im having trouble with troubleshooting. its giving me a couple errors but i dont know what they mean
我正在设置一个不和谐的机器人。它会成为一个具有特定命令的通信机器人。我的机器人现在无法启动,因为它给了我以下错误代码
E:\FLRP Communication\package.js:20
bot.command.set(props.help.name, props);
^
TypeError: Cannot read property 'set' of undefined
at jsfile.forEach (E:\FLRP Communication\package.js:20:17)
at Array.forEach (<anonymous>)
at fs.readdir (E:\FLRP Communication\package.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);
我正在设置一个不和谐的机器人。它会成为一个具有特定命令的通信机器人。我的机器人现在无法启动,因为它给了我以下错误代码
E:\FLRP Communication\package.js:20
bot.command.set(props.help.name, props);
^
TypeError: Cannot read property 'set' of undefined
at jsfile.forEach (E:\FLRP Communication\package.js:20:17)
at Array.forEach (<anonymous>)
at fs.readdir (E:\FLRP Communication\package.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);