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

174
Vistas
Discord JS v13 Getting var's from an object and putting them all in a embed

Ive never worked with objects and dont know how they work. Tried searching it up but doesnt come up with what im looking for. I want to get peoples username in sample and put them all into an embed to display whos online

  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));
  }

returns

{
  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
}

In the object

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

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Your code doesn't look to bad, just a few issues i see.

Since the player list is an array you need to correct this line first,
because you can't destructure the array like that:

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

From there on you now have an array of the playerlist and you can use the for loop
To add fields or add them to a string.

// 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);

I hope that helped!
If someone has a better / more efficient way, let me know :)

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