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

925
Vistas
How do I get the owners of all the guilds in discord.js v13?

I am trying to get the owner of all the guilds my bot is in, so I can send a newsletter to them. So far I have this:

const guilds = message.client.guilds.cache.map(guild => guild);
guilds.forEach(guild => {
    const owner = message.client.users.cache.get(guild.ownerId)
    owner.send({embeds: [newsembed]})
    .catch(console.error());
});

which gets the guilds, then gets the owner id, then gets the owner from the id in the cache. Now normally I would use .fetchOwner() but I cannot use await it in a forEach loop, but if you have a suggestion for that please do tell. When running the code listed above I get the error:

            owner.send({embeds: [newsembed]})
                  ^

TypeError: Cannot read properties of undefined (reading 'send')

I am not sure why I get this error, maybe the owner is not in the cache? I have tried fetching them in a forEach loop but I cant use await guild.fetchOwner() in forEach loops. I tried putting the forEach loop in an async function, same problem. Any help is appreciated, thanks!

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

0

You can make the forEach() loop asynchronous

const guilds = message.client.guilds.cache.map(guild => guild);
guilds.forEach(async guild => {
    const owner = await guild.fetchOwner();
    owner.send({embeds: [newsembed]})
       .catch(console.error());
});
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