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

465
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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