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

177
Views
Discord JS v13 Obtener var's de un objeto y ponerlos todos en una inserción

Nunca he trabajado con objetos y no sé cómo funcionan. Intenté buscarlo pero no aparece lo que estoy buscando. Quiero obtener el nombre de usuario de las personas en la muestra y colocarlos todos en una inserción para mostrar quién está en línea

 if (command === "status") { util.status('server', 25565, options) .then( (result) => { console.log(result) dumbarry = result.players.sample.names console.log(dumbarry) if (!dumbarry) return message.channel.send("No one is online") let embed = new MessageEmbed() .setTitle("Mincraft Players Online") for (let i = 0; i < dumbarry.length; i++) { embed.addField(dumbarry[i], 'is online') } message.channel.send(embed) } ) .catch((error) => console.error(error)); }

devoluciones

 { version: { name: 'Paper 1.18.2', protocol: 758 }, players: { online: 1, max: 100, sample: [ [Object] ] }, motd: { raw: '§fWelcome to hell', clean: 'Welcome to hell', html: '<span><span style="color: #FFFFFF;">Welcome to hell</span></span>' }, favicon: null, srvRecord: { host: 'server', port: 25600 }, roundTripLatency: 139 }

en el objeto

[ { id: '8c075091-7837-41ca-9d9c-bb618843b15f', name: 'newdabz' }

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Su código no se ve mal, solo veo algunos problemas.

Dado que la lista de jugadores es una matriz, primero debe corregir esta línea,
porque no puedes desestructurar la matriz así:

 - dumbarry = result.players.sample.names + let dumbarry = result.players.sample

A partir de ahí, ahora tiene una matriz de la lista de reproductores y puede usar el bucle for
Para agregar campos o agregarlos a una cadena.

 // Sample 1 for (let i = 0; i < dumbarry.length; i++) { embed.addField(dumbarry[i].name, 'is online') } // Sample 2 for (let player of dumbarry) { embed.addField(player.name, 'is online.'); } // With string let string = ''; for (let player of dumbarry) { string += `**${player.name}** is online!\n` } embed.setDescription(string);

¡Espero que haya ayudado!
Si alguien tiene una forma mejor / más eficiente, hágamelo saber :)

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!