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

152
Visualizações
How would I go thru my members list and remove ! from someone’s username?

I'm trying to make my Discord Bot[v13] go thru all the members in the server and remove ! and extra spaces from theirs username. For example the bot would change someone nickname from ! net-tech- to just net-tech- by removing the ! and extra spaces. So far I have

message.guild.members.fetch().then(fetchedMembers => {
      const target_users = fetchedMembers.filter(member => member.user.username.startsWith("!"));

but I don't know how I would rename them to their name without ! at the start.

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

0

You could try using string replace. e.g.

var name = "! net-tech-"
// replace ! with "" and replace the space with ""
var newName = name.replace("!","").replace(" ","")

newName should give you "net-tech-"

Alternatively, you could use an if statement to check if the name starts with "!", e.g.

if (name[0] === "!") {
    // get the string from 2nd character onwards
    var newName = name.slice(1)
}

about 4 years ago · Juan Pablo Isaza Relatório

0

Fetch The first step would be to fetch all the members, which you've done so far.

Filter Next filter all members with usernames that have ! or any extra spaces.

If you want to replace only the ! if they are at the start you would use String#startsWith(), for any ! in the username use String#includes().

To remove all extra spaces you can use the Regular Expression / +/g

Traverse Loop through the resulting members and change their nicknames

const targetChar = '!';
const extraSpaces = / +/g;

message.guild.members.fetch().then(fetchedMembers => {
   // Use startsWith() for only starting "!", Use includes for any "!"
   const membersToRename = Array.from(fetchedMembers.filter(m => m.user.username.includes(targetChar) || m.user.username.match(extraSpaces).length));

   if (!membersToRename.length) return;

   // Use replace() for only the first, replaceAll() for all
   membersToRename.forEach(m => {
      const newNickname = m.user.username
         .replaceAll(targetChar, '')
         .replaceAll(extraSpaces, '');
      m.setNickname(newNickname)
         .catch(console.error);
   });
});

Warning This could be considered API spam since you're changing information in masses, especially if used in large servers.

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