不和谐.js - 类型错误:无法读取未定义的属性(读取"set")



这是在main.js:

const { Client, Intents, DiscordAPIError } = require('discord.js');
const Discord = require('discord.js');
const client = new Discord.Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
const prefix = 'js!';
const fs = require('fs');
client.command = new Discord.Collection();
fs.readdir("./commands/", (err, files) => {
if(err) console.error(error)
let jsfiles = files.filter(f => f.split(".").pop() === "js")
if (jsfiles.length <= 0) {
return console.log("No commands to log in FOLDER NAME")
}
console.log(`Loading ${jsfiles.length} commands from FOLDER NAME...`)
jsfiles.forEach((f,i) => {
let props = require(`./commands/${f}`)
console.log(`${i + 1}: ${f} loaded!`)
client.commands.set(f, props)
})
});
client.once('ready',() => {
console.log('bot is on')
});
client.on('message', message =>{
if(!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
if(command === 'ping'){
let cmd = client.commands.get(command+".js")
if (cmd) cmd.run(bot, message, args, prefix)
} 
});
client.login('Prefix')

在ping。js中:

const { Client, Intents, DiscordAPIError } = require('discord.js');
const Discord = require('discord.js')
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
module.exports.run = async (client, message, args, prefix) => {
var ping = Date.now() - message.createdTimestamp + " ms";
message.channel.send('Ma ping is' + ` ${Date.now() - message.createdTimestamp}` + 'ms')
};
module.exports.help = {
name: "ping",
usage: "Ping Command",
};

但是如果我用命令node .在终端运行main.js,我得到这个错误:

Loading 1 commands from FOLDER NAME...
1: ping.js loaded!
/home/ender/Desktop/Projects & Stuff/Coding/Discord Bot (JS)/main.js:23
client.commands.set(f, props)
^
TypeError: Cannot read properties of undefined (reading 'set')
at /home/ender/Desktop/Projects & Stuff/Coding/Discord Bot (JS)/main.js:23:23
at Array.forEach (<anonymous>)
at /home/ender/Desktop/Projects & Stuff/Coding/Discord Bot (JS)/main.js:20:13
at FSReqCallback.oncomplete (node:fs:188:23)

我使用linux作为我的主要操作系统,我使用的node.js版本是v16.11.1和npm版本是8.0.0!

请帮助,我最近开始使用discord.js后,我意识到discord.py已经死了,我需要帮助!

编辑一个我的文件是这样组织的:图1

正如@ mrmythyth指出的那样,唯一的问题是我忘记了一个" "在client.command = new Discord.Collection();线。在我加上" "最后,它工作良好-没有其他错误,所以这是我自己的问题的答案!