![](/img/trans.png)
[英]Need help -> Uncaught (in promise) TypeError: Cannot read property 'length' of undefined
[英]Cannot read property 'name' of undefined, i need some help here
const fs = require('fs');
function loadCommands(client) {
fs.readdir('commands/', (err, files) => {
if (err) console.log(err);
const jsfile = files.filter(f => f.split('.').pop() === 'js');
if (jsfile.length <= 0) {
return console.log('Bot Couldn\'t Find Commands in commands Folder.');
}
jsfile.forEach((f, i) => {
const pull = require(`../commands/${f}`);
client.commands.set(pull.config.name, pull);
pull.config.aliases.forEach(alias => {
bot.aliases.set(alias, pull.config.name);
});
});
});
}
module.exports = {
loadCommands
}
我不知道為什么它在這里的錯誤看起來很棒的代碼......
錯誤在client.commands.set(pull.config.name, pull); 在bot.aliases.set(alias, pull.config.name); 顯示未定義。
我需要一些幫助,我正在嘗試為我的機器人制作一個自定義前綴,我真的需要這個代碼!
../commands/whateverFile.js
中的文件之一不導出config
,或者導出config
但沒有在其上放置.name
屬性。 您沒有向我們展示任何這些文件,因此很難猜測問題所在。
你可以試試這個來找出哪個文件是壞的。
jsfile.forEach((f, i) => {
const pull = require(`../commands/${f}`);
if (!pull || !pull.config || !pull.config.name) {
throw new Error (`bogus require file ${f}`)
}
client.commands.set(pull.config.name, pull);
pull.config.aliases.forEach(alias => {
bot.aliases.set(alias, pull.config.name);
});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.