Este error no fue un problema hasta hoy. Cada vez que ejecuto mi bot discordjs, me da un TypeError que dice "No se pueden leer las propiedades de undefined (leyendo 'toLowerCase')"
Aquí está mi código
const { readdirSync } = require('fs'); const { Collection } = require('discord.js'); client.commands = new Collection(); const events = readdirSync('./events/').filter(file => file.endsWith('.js')); console.log(`Loading events...`); for (const file of events) { const event = require(`../events/${file}`); console.log(`-> Loaded event ${file.split('.')[0]}`); client.on(file.split('.')[0], event.bind(null, client)); delete require.cache[require.resolve(`../events/${file}`)]; }; console.log(`Loading commands...`); readdirSync('./commands/').forEach(dirs => { const commands = readdirSync(`./commands/${dirs}`).filter(files => files.endsWith('.js')); for (const file of commands) { const command = require(`../commands/${dirs}/${file}`); console.log(`-> Loaded command ${command.name.toLowerCase()}`); client.commands.set(command.name.toLowerCase(), command); delete require.cache[require.resolve(`../commands/${dirs}/${file}`)]; }; });cuando ejecuto el bot, la salida es así
Loading events... -> Loaded event interactionCreate -> Loaded event messageCreate -> Loaded event ready Loading commands... TypeError: Cannot read properties of undefined (reading 'toLowerCase') at /home/runner/Saeki-Miyako-Bot/src/loader.js:26:55 at Array.forEach (<anonymous>) at Object.<anonymous> (/home/runner/Saeki-Miyako-Bot/src/loader.js:21:28) at Module._compile (node:internal/modules/cjs/loader:1101:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10) at Module.load (node:internal/modules/cjs/loader:981:32) at Function.Module._load (node:internal/modules/cjs/loader:822:12) at Module.require (node:internal/modules/cjs/loader:1005:19) at require (node:internal/modules/cjs/helpers:102:18) at Object.<anonymous> (/home/runner/Saeki-Miyako-Bot/main.js:43:1) npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! music-bot@12.22.6 start: `node main.js` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the music-bot@12.22.6 start script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! /home/runner/.npm/_logs/2021-10-26T03_01_19_546Z-debug.log exit status 1Eso significa que sus comandos (importación de archivos) no tienen todos la misma estructura (con la propiedad 'nombre').
Si los comandos sin nombre no son críticos, puede filtrarlos:
for (const file of commands) { const command = require(`../commands/${dirs}/${file}`); if (!command || !command.name) { console.warn(`Name is missing in 'commands/${dirs}/${file}'`) continue; } console.log(`-> Loaded command ${command.name.toLowerCase()}`); client.commands.set(command.name.toLowerCase(), command); delete require.cache[require.resolve(`../commands/${dirs}/${file}`)]; };Como no tengo acceso a sus sistemas de archivos, no puedo ver el contenido de los archivos. Pero supongo que el nombre solo falta en parte del archivo (comando).