Estoy trabajando en este bot de discordia con un controlador de comandos, todos los comandos están en sus propios archivos que importo al archivo principal.
Este es mi código:
const { Client, Intents } = require("discord.js"); const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] }); client.commands = new Discord.Collection(); const fs = require('fs'); const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js')) for(const file of commandFiles){ const command = require(`./commands/${file}`) client.commands.set(command.name, command) } const { prefix, token } = require('./config.json') client.once('ready', () => { console.log('BOT IS READY') }) 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 === 'charlongolo'){ client.commands.get('charlongolo').execute(message, args) } else if(command === 'timster'){ client.commands.get('timster').execute(message, args) } }) client.login(token);El error es cómo importas disord.js y luego lo usas, por lo que hay dos formas de hacerlo: puedes importar todo el módulo o importar a través de la desestructuración de objetos.
const Discord = require('discord.js'); ... const client = new Discord.Client({ intents: [Discord .Intents.FLAGS.GUILDS, Discord .Intents.FLAGS.GUILD_MESSAGES] }) client.commands = new Discord.Collection(); const { Client, Intents, Collection } = require("discord.js"); ... const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] }); client.commands = new Collection();