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

307
Vistas
Ping bot response time command not working

Why is this command not working I am new to coding and would really appreciate some help I am simply trying to get a bot response time ping command to work this is not producing any errors anymore but it doesn't work either and as I am not getting any errors I am having difficulty discovering the problem on my own.

client.on('messageCreate', message => {
    if (message.channel.type != 'text' || message.author.bot)
      return;
  
    let command = message.content.split(' ')[0].slice(1);
    let args = message.content.replace('.' + command, '').trim();
  
    switch (command) {
      case 'ping': {
        message.channel.send('Pong! (~ ' + client.ping + 'ms)');
        break;
      }
  
  
      case 'uptime': {
        // client.uptime is in millseconds
        // this is just maths, I won't explain much of it
        // % is modulo, AKA the remainder of a division
        let days = Math.floor(client.uptime / 86400000);
        let hours = Math.floor(client.uptime / 3600000) % 24;
        let minutes = Math.floor(client.uptime / 60000) % 60;
        let seconds = Math.floor(client.uptime / 1000) % 60;
  
        message.channel.send(`__Uptime:__\n${days}d ${hours}h ${minutes}m ${seconds}s`);
        break;
      }
    }
  });
about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

The issue is that you're checking if GuildChannel#type is text, which is not a valid ChannelType.

Instead, try using GUILD_TEXT.

client.on('messageCreate', message => {
    if (message.channel.type !== 'GUILD_TEXT' || message.author.bot)
        return;

    let command = message.content.split(' ')[0].slice(1);
    let args = message.content.replace('.' + command, '').trim();

    switch (command) {
        case 'ping': {
            message.channel.send('Pong! (~ ' + client.ping + 'ms)');
            break;
        }


        case 'uptime': {
            // client.uptime is in millseconds
            // this is just maths, I won't explain much of it
            // % is modulo, AKA the remainder of a division
            let days = Math.floor(client.uptime / 86400000);
            let hours = Math.floor(client.uptime / 3600000) % 24;
            let minutes = Math.floor(client.uptime / 60000) % 60;
            let seconds = Math.floor(client.uptime / 1000) % 60;

            message.channel.send(`__Uptime:__\n${days}d ${hours}h ${minutes}m ${seconds}s`);
            break;
        }
    }
});

Note: In April of 2022 access to message content will become a Privileged Intent. I really recommend you to switch to Slash Commands.

Read more here: Message Content: Privileged Intent for Verified Bots

about 4 years ago · Santiago Trujillo 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