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

462
Views
Discord Bot Doesn't reply back (Node.js)

I'ven struggling creating a bot for my discord server so i used the initial code for the discord bot from discordjs.guide and added a simple command to respond to "ping", i wanted to prove what i did wrong before... but i get no response from the bot. I already give it permissions with the invite link and with a role, someone can tell me what's wrong with the code? I installed discord.js and dotenv

// Require the necessary discord.js classes
const { Client, Intents } = require('discord.js');
const { token } = require('./config.json');

// Create a new client instance
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });

// When the client is ready, run this code (only once)
client.once('ready', () => {
    console.log('Ready!');
});

client.on('message', function(msg){
    if(msg.content === 'ping'){
        msg.reply('pong');
    }
});

// Login to Discord with your client's token
client.login(token);
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Your code is missing the GUILD_MESSAGES intent. Simply add it into your intents and your bot should respond to messages. Pay in mind that discord is removing message intents after April 30th so you'd need to go into https://discord.com/developers and into the bot section, turn on message intents.

// Require the necessary discord.js classes
const { Client, Intents } = require('discord.js');
const { token } = require('./config.json');

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

// When the client is ready, run this code (only once)
client.once('ready', () => {
    console.log('Ready!');
});

client.on('message', function(msg){
    if(msg.content === 'ping'){
        msg.reply('pong');
    }
});

// Login to Discord with your client's token
client.login(token);

Pay in mind that discord is removing message intents after April 30th so you'd need to go into https://discord.com/developers and into the bot section, turn on message intents.

about 4 years ago · Juan Pablo Isaza Report

0

it's because the client.on("message") has been deprecated

And you should define on your discord client the GUILD_MESSAGES as this

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

and the event to receive the message on your server would be

client.on('messageCreate', function(msg){
    if(msg.content === 'ping'){
        msg.reply('pong');
    }
});

Docs of "messageCreate" event

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!