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

175
Visualizações
Ban user if they mention over 5 people

Heyo Axmyo here,

I want to autoban user if they mention over 5 humans, not bots

but the code I tried to use doesn't do anything..

Any help would be appreciated!

client.on("message", message => {
  if(message.mentions.members.size > 5) {
    message.author.ban();
  } 
})
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You're in the right direction, your if statement is correct.

message.author returns a User.

but .ban() is available only on GuildMember.

So you need to convert the User to a GuildMember. Luckily the message object contains the Guild that it was sent in, so you can do the following:

client.on("message", message => {
  if(message.mentions.members.size > 5) {
    const user = message.author;
    const guildMember = message.guild.member(user);
    guildMember.ban();
  } 
})

Notice that .ban() returns a promise, so it might be a good idea to do the following, if you want to do additional things after the ban:

client.on("message", async message => {
  if(message.mentions.members.size > 5) {
    const user = message.author;
    const guildMember = message.guild.member(user);
    await guildMember.ban();

    // Do other things...
  } 
})

Edit

message object has a member property on it, thanks Itamar S

client.on("message", async message => {
  if(message.mentions.members.size <= 5) return;

  await message.member.ban();
  // Do other things... 
})
over 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