Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

302
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda