Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

922
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda