'TypeError: Cannot read properties of undefined (reading 'name') discord.js [closed]
I'm learning discord.js and I'm trying to follow this tutorial on discordjs.guide, but this error occurs:
client.commands.set(command.data.name, command);
^
TypeError: Cannot read properties of undefined (reading 'name')
index.js code on the errored part:
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
}
If you need more code, please tell it to me.
Solution 1:[1]
delete the data on your code line
client.commands.set(command.name, command); //this will set your command name
Edit: I didn't recognize the .ts but I'm sure it's the same properties with .js
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Zsolt Meszaros |
