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

98
Vistas
Can't find a way to make my discord.js bot detect messages
import { Client, Intents } from 'discord.js';
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });

client.once('ready', () => {
    console.log('Ready!');
});
client.on("message", async msg => {
    if (msg.content === "ping") {
        console.log("ping")
        msg.reply("pong")
    }
});

client.login(token);

I'm using discord.js v13, the bot logs in correctly and outputs "Ready!" and then when I type a message in the server it's online in it doesn't even console.log

Any help appreciated, thanks in advance.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You need the GUILD_MESSAGES intent enabled to receive message events. Additionally, as CcmU said, the message event is deprecated, and should be replaced with messageCreate.

// ...
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
// ...
client.on("messageCreate", async msg => { /* ... */ })
// ...
about 4 years ago · Juan Pablo Isaza Denunciar

0

As you can see from the docs, the event message is deprecated. You can use instead a listener for the event messageCreated if you want to listen for any new message.

So you can try something like

client.on('messageCreate', async msg => {
  if (msg.content === "ping") {
    console.log("ping");
    msg.reply("pong");
  }
});

EDIT:

As @chickensalt pointed out, you have to declare in your Intents the appropriate one for handling messages, that is Intents.FLAGS.GUILD_MESSAGES. So, when creating your Client:

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

But remember to use the correct Intent for your needs, because you could have some trouble in handling memory correctly. As the docs suggests:

For larger bots, client state can grow to be quite large. We recommend only storing objects in memory that are needed for a bot's operation. Many bots, for example, just respond to user input through chat commands. These bots may only need to keep guild information (like guild/channel roles and permissions) in memory, since MESSAGE_CREATE and MESSAGE_UPDATE events have the full member object available.

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