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

300
Views
¿Cómo haría para agregar argumentos a mis comandos discord.js?

¿Cuál sería la mejor manera de agregar argumentos a mis comandos de discordia? por ejemplo, !ban {nombre de usuario} ¡Cualquier ayuda sería muy apreciada!

 const Client = new Discord.Client({ intents: ["GUILD_MESSAGES", "GUILDS"], }); const botOptions = { token: "", prefix: ['!','.'], commands: [ { name: ['joined','j'], roles: ['@everyone'], channels: [], method: (msg) => require('./userJoined')(msg), }, ], }; Client.on("messageCreate", (msg) => { const prefix = msg.content.split('')[0]; const commandName = msg.content.split(prefix)[1].toLowerCase(); const checkPrefix = botOptions.prefix.some((x) => x === prefix); const findCommand = botOptions.commands.find(command => command.name.includes(commandName)); if (typeof findCommand !== 'undefined' && checkPrefix) { const { name, roles, channels, method } = findCommand; const rolePermission = msg.member.roles.cache.some(role => roles.includes(role.name.toLowerCase())); const channelPermission = channels.includes(msg.channelId); if (channelPermission || channels.length === 0 && rolePermission) { method(msg); } } });
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Si está tratando de agregar argumentos (argumentos), primero debe dividir el mensaje en una matriz

 let messageArray = message.content.split(" ");

Ahora solo tiene una matriz llena de argumentos, el primer argumento en la variable messageArray es básicamente el comando que se está ejecutando, después de eso, el resto son solo los argumentos del mensaje.

 let messageArray = message.content.split(" "); let cmd = messageArray[0]; // getting the command, this line can be removed let args = messageArray.slice(1)

En el ejemplo anterior, cortamos la variable messageArray en su segundo elemento, que es el primer argumento del mensaje (sin incluir el cmd).

¡Así que aquí hay un pequeño ejemplo de cómo funciona esto !mix 3845345343 4353943

3845345343 siendo argumentos args[0]
4353943 siendo argumentos args[1]

y así sucesivamente si tienes más argumentos

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!