Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

166
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!