Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

93
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!