Tengo un proyecto y planeo activar más de un bot en este proyecto, pero me encontré con ese problema al activar mi primer bot.
Versión de Discord.js: 13.6.0 Versión de Node.js: v16.13.2
Os dejo el enlace del proyecto glitch. https://glitch.com/edit/#!/super-winter-oregano
PRINCIPAL 1
require('./botlar/botlist2/botlist2.js')PRINCIPAL 2
const { Client, Intents,Collection } = require('discord.js'); const fs = require('fs') const config = require("./ayarlar.json") const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] }); client.commands = new Collection(); const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js')); const eventFiles = fs.readdirSync('./events').filter(file => file.endsWith('.js')); for (const file of commandFiles) { const command = require(`./commands/${file}`); client.commands.set(command.name, command); } for (const file of eventFiles) { const event = require(`./events/${file}`); if (event.once) { client.once(event.name, (...args) => event.execute(...args, client)); } else { client.on(event.name, (...args) => event.execute(...args, client)); } } process.on('unhandledRejection', error => { console.error('Unhandled promise rejection:', error); }); client.login(process.env.token2)ERROR
node:internal/fs/utils:344 throw err; ^ Error: ENOENT: no such file or directory, scandir './commands' at Object.readdirSync (node:fs:1390:3) at Object.<anonymous> (/app/botlar/botlist2/botlist2.js:8:25) 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> (/app/index.js:1:1) at Module._compile (node:internal/modules/cjs/loader:1101:14) { errno: -2, syscall: 'scandir', code: 'ENOENT', path: './commands' }Esto es . coincide con /app/botlar debido a que botlist2.js se ejecuta en el archivo index.js . Entonces, por ejemplo, necesitarías hacer algo como esto:
fs.readdirSync('./botlar/botlist2/commands');