gpt4 book ai didi

javascript - Discord.js 类型错误 : Cannot read property 'name' of undefined

转载 作者:行者123 更新时间:2023-12-03 02:10:35 26 4
gpt4 key购买 nike

const botconfig = require("./botconfig.json");
const tokenfile = require("./token.json");
const Discord = require("discord.js");
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("Couldn't find commands.");
return;
}

jsfile.forEach((f, i) =>{
let props = require(`./commands/${f}`);
console.log(`${f} loaded!`);
bot.commands.set(props.help.name, props);
});

});


bot.on("ready", async () => {
console.log(`${bot.user.username} is online on ${bot.guilds.size} servers!`);

bot.user.setActivity("!help | website.xyz", {type: "WATCHING"});

//bot.user.setGame("on SourceCade!");
});

bot.on("message", async message => {
if(message.author.bot) return;
if(message.channel.type === "dm") return;

let prefix = botconfig.prefix;
let messageArray = message.content.split(" ");
let cmd = messageArray[0];
let args = messageArray.slice(1);

let commandfile = bot.commands.get(cmd.slice(prefix.length));
if(commandfile) commandfile.run(bot,message,args);

});

bot.login(tokenfile.token);

这是我的索引文件夹,当我尝试运行机器人时,出现此错误。我已经尝试了一切,但我在这方面并不是最好的,因为我仍在学习,所以任何帮助将不胜感激!谢谢

C:\Users\Luca\Desktop\DiscordJS\RedHQ-Bot\index.js:21
bot.commands.set(props.help.name, props);
^

TypeError: Cannot read property 'name' of undefined
at jsfile.forEach (C:\Users\Luca\Desktop\DiscordJS\RedHQ-Bot\index.js:21:33)
at Array.forEach (<anonymous>)
at fs.readdir (C:\Users\Luca\Desktop\DiscordJS\RedHQ-Bot\index.js:18:10)
at FSReqWrap.oncomplete (fs.js:135:15)
[nodemon] app crashed - waiting for file changes before starting...

最佳答案

您的命令处理程序没有

exports.conf = {
aliases: ['Stuff', 'AlsoStuff']
};
exports.help = {
name: "More Stuff", description: "SillyStuff.", usage: ".SeriousStuff"
}

这就是为什么您会返回名称未找到错误的原因。因为在它正在查找的代码中,它不存在。

关于javascript - Discord.js 类型错误 : Cannot read property 'name' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49589728/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com