He estado luchando para que funcione el controlador de comandos de mi nuevo bot Discord, mientras ve los archivos de comandos (como lo indica su entrada de registro al inicio que indica la cantidad de comandos que ha cargado) no está enviando los mensajes, o ni siquiera los está ejecutando.
Aquí está mi código:
const { Client, Intents, Collection } = require('discord.js'); const { token, ownerid, statuses, embedColors, prefix } = require('./cfg/config.json'); const client = new Client({ intents: [Intents.FLAGS.GUILDS] }); const fs = require('fs'); const { config } = require('process'); client.commands = new Collection(); const commands = []; const cmdfiles = fs.readdirSync('./cmds').filter(file => file.endsWith('.js')); client.once('ready', () => { console.clear console.log(`Ready to go, Found ${cmdfiles.length} commands and ${statuses.length} statuses!`) setInterval(() => { var status = Math.floor(Math.random() * (statuses.length -1) +1) client.user.setActivity(statuses[status]); }, 20000) }), client.on("error", (e) => console.log(error(e))); client.on("warn", (e) => console.log(warn(e))); // Command Handler for (const file of cmdfiles) { const command = require(`./cmds/${file}`); commands.push(command.data); } client.on('messageCreate', message => { if (!message.content.startsWith(prefix) || message.author.bot) return; const args = message.content.slice(prefix.length).trim().split(/ +/); const command = args.shift().toLowerCase(); if (!client.commands.has(command)) { embeds: [{ title: ":x: Oopsie!", color: config.embedColors.red, description: `Command ${args.[0]} doesn't exist! Run ${config.prefix}help to see the avaliable commands!`, footer: app.config.footer + " Something went wrong! :(" }]; } else { try { client.commands.get(command).execute(message, args); } catch (error) { console.error(error); embeds: [{ title: ":x: Oopsie!", description: "Command execution failed", fields: [ { name: "Error Message", value: `${e.message}` } ], footer: app.config.footer + " Something went wrong :(" }]; } message.channel.send }}); client.login(token);y el comando de prueba es
module.exports = { name: "test", description: "does as it implies, dingusA", async execute(client, message, args) { message.channel.send("This is a message!"); } }Necesitas la intención GUILD_MESSAGES para recibir mensajes en los gremios.
Agregue la siguiente intención en su código
const client = new Client({ intents: [ Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES ] }) Esto se aplica a otras cosas también, por ejemplo. DIRECT_MESSAGES para DM y etc.