TypeError: Cannot read properties of undefined (reading 'name') discord.js

TypeError: Cannot read properties of undefined (reading 'name') discord.js

我正在学习 discord.js 并且我正在尝试遵循 this tutorial on discordjs.guide,但出现此错误:

client.commands.set(command.data.name, command);
                                 ^

TypeError: Cannot read properties of undefined (reading 'name')

index.js 错误部分的代码:

const fs = require('node:fs');
const client = new Discord.Client({ intents: 32767 });
client.commands = new Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.ts'));

for (const file of commandFiles) {
    const command = require(`./commands/${file}`);
    client.commands.set(command.data.name, command); // errored part
}

如果您需要更多代码,请告诉我。

删除代码行中的 data

client.commands.set(command.name, command); //this will set your command name

编辑:我不认识 .ts,但我确定它与 .js

具有相同的属性