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

232
Visualizações
Ban outside server users in Discord.js 12.5.1

I am trying to make a ban command that can ban someone using his ID and it works great, the problem is that when I try to ban a user that isn't on the server (using his ID) or only use 1 digit, the command doesn't work and the bot crashes. I think the problem is caused by the if statement but I'm not sure.

Here's my code :

  let args = messageArray.slice(1);

  if(message.content.startsWith(prefix + 'ban')) {
      let toBan = message.guild.members.cache.get(args[0]) || message.mentions.members.first() || message.guild.members.cache.find(x => x.user.username.toLowerCase() === args.slice(0).join(" ") || x.user.username === args[0]);
      if(!args) return message.channel.send('You need to mention a user!')
      if (!message.member.hasPermission("VIEW_AUDIT_LOG")) return message.channel.send("You don't have enough permissions.")
      if (!message.guild.me.hasPermission("BAN_MEMBERS")) return message.channel.send("I don't have enought permissions.")
             if(!toBan.bannable) return message.channel.send("I can't ban that user!")
      if(toBan === message.author) return message.channel.send("No.")
      if(toBan.roles.highest.position >= message.member.roles.highest.position) return message.channel.send("You can't ban anyone that have a high or same role that you have.")

      const reason = args[1] || "Undefined";

      member.ban(`${toBan}`, {
        reason: reason
      })
           message.channel.send(`${toBan} Has been banned of the server by ${message.author}!`)
       }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can use GuildMemberManager.ban(), which takes a UserResolvable. It can be a User, a GuildMember, or even just a Snowflake (ID).


Simple Example:

message.guild.members.ban("12345678901234567");
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