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

231
Views
Prohibir a los usuarios externos del servidor en Discord.js 12.5.1

Estoy tratando de hacer un comando de prohibición que pueda prohibir a alguien usando su ID y funciona muy bien, el problema es que cuando trato de prohibir a un usuario que no está en el servidor (usando su ID) o solo uso 1 dígito, el El comando no funciona y el bot falla. Creo que el problema se debe a la instrucción if, pero no estoy seguro.

Aquí está mi código:

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

0

Puede usar GuildMemberManager.ban() , que toma un UserResolvable . Puede ser un User , un GuildMember o incluso simplemente un Snowflake de nieve (ID).


Ejemplo sencillo:

 message.guild.members.ban("12345678901234567");
about 4 years ago · Juan Pablo Isaza 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!