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

445
Vistas
I'm trying to program my first discord bot but its not responding to the command (javascript)

I've been following a video on how to code commands for beginners. I tried this code but it's not responding to the command I checked the permissions no issues there as well. I copied his code all the same and did not also work.

const { Client, Intents } = require('discord.js');

const client = new Client( );

client.once('ready' , () => {
    console.log('bot is online');
    
const token = ' Token ';

});


const PREFIX = '!';


client.on('message ' , message=>{

    let args = message.content.substring(PREFIX.length).split(" ");

    switch(args[0]){
        case 'ping':
            message.reply('pong!');
        break;

    }
})






client.login ( token );
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

It should be

client.on('message', //rest of code

instead of

client.on('message ', //rest of code
about 4 years ago · Juan Pablo Isaza Denunciar

0

The first thing I would do is to adjust the permissions in your client's declaration.

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

then I would try changing the event listener, the last version deprecated some old events

try

client.on("messageCreate", (message) => {

  let args = message.content.substring(PREFIX.length).split(" ");

  switch(args[0]){
    case 'ping':
      message.reply('pong!');
    break;

  }
});
about 4 years ago · Juan Pablo Isaza Denunciar

0

So, I checked your code right now and since you're only running a few commands and nothing crazily advanced, I'd suggest just using an if statement to check the content of the message and IF It meets the condition to return something, here's the code that I tested and It works, It's a lot simpler and easily modifiable. I'd also suggest adjusting the Intents like Armandas Astrauskas said, and you shouldn't declare stuff inside client methods, like the ready one where you declared the token in, AND if you're using discord.js v13 you'd have to use messageCreate.

const {Client,Intents } = require('discord.js');

const client = new Client();
const token = ' Token ';


client.on('ready', () => {
  console.log('bot is online');
});


const PREFIX = '!';


client.on('message', message => {

  if (message.content == `${PREFIX}ping`) {
    message.reply("pong!")
  }

})

client.login(token);
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