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

309
Visualizações
how to remove a AFK from the nickname without say the prefix

so I make a simple AFK command like this

client.on('message', message => {
  if (message.content.includes('!afk')) {
      message.member.setNickname(`[AFK] ${message.member.displayName} `).catch(error => console.log(error));
  }
  
  if (message.content === '!back') {
    message.member.setNickname(message.member.displayName.replace('[AFK] ', )).catch(error => console.log(error));

  }

 
  
  
});

and I want If the user is afk and then user chat like "hi" the [AFK] is gone without say the prefix "!back"

How can I do that?

Thank You for helping me (:

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

If I understand correctly, you are asking to delete the AFK status when the player types something again. I made a rough solution using JS Set that should work well with a small set of users, but it may require additional tweaks for large servers.

Basically, when a player types !afk it is included in the set of AFK players and when he/she/it comes back and types something, its name is deleted from the set and its nickname updated. I am not sure if the message.member.id exists and it is the correct field to track the player (EDIT: Yes, it is), but the main idea is to keep record of something unique for each afk player.

    const afkPlayers = new Set();
    
    client.on('message', message => {
      if (message.content.includes('!afk')) {
          afkPlayers.add(message.member.id);
          message.member.setNickname(`[AFK] ${message.member.displayName} `).catch(error => console.log(error));
      }
      
      if(afkPlayers.member.has(message.member.id)){
        afkPlayers.member.delete(message.member.id);
        message.member.setNickname(message.member.displayName.replace('[AFK] ', )).catch(error => console.log(error));
      }
      
});
about 4 years ago · Juan Pablo Isaza Relatório

0

I don't really know how Discord works and when exactly the "message" event is triggered, but it seems to me that you could probably do it even without the set, as proposed by @TheCave3:

client.on('message', message => {
  const pref='[AFK] ';
  if (message.content.includes('!afk'))
    message.member.setNickname(pref+message.member.displayName).catch(error => console.log(error));
  else if (message.member.displayName.slice(0,pref.length)===pref)
    message.member.setNickname(message.member.displayName.slice(pref.length)).catch(error => console.log(error));
});
about 4 years ago · Juan Pablo Isaza 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