Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

154
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda