Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

233
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda