Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

157
Vistas
Discord.JS bot not replying to commands nor returning a error in console regarding it

I've been struggling to get my new Discord bot's command handler to work, While it is seeing the command files (as indicated by its log entry on startup stating the amount of commands it has loaded) it either isn't sending the messages, or it isn't even executing them.

Here's my code:

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);

and the test command is

module.exports = {
    name: "test",
    description: "does as it implies, dingusA",
    async execute(client, message, args) {
        message.channel.send("This is a message!");
    }
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You need the GUILD_MESSAGES intent in order to receive messages in guilds.
Add the following intent in your code

const client = new Client({ intents: [
    Intents.FLAGS.GUILDS, 
    Intents.FLAGS.GUILD_MESSAGES ] 
})

This applies to other things as well eg. DIRECT_MESSAGES for DMs and etc.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda