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

215
Visualizações
Discordjs DM all server members

I'm trying to DM all server members by a bot trough a command and it only DMs 4 people that are Administrators

message.guild.members.cache.forEach(member => { // Looping through each member of the guild.
    // Trying to send a message to the member.
    // This method might fail because of the member's privacy settings, so we're using .catch

    member.send(`hi`)

    .catch(() => (`Couldn't DM member ${member.user.tag}`));
    message.channel.send(`Success`)

        .catch(console.error);
});
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

This operation can be extremely time-consuming. @SuleymanCelik's answer was partially correct because not every user is stored in the bot member cache. To get every single user in the server, you need to make a fetch() call for all the users like this.

guild.members
    .fetch()
    .then(members => members.forEach(member => {
        member
            .send("Hello!")
            .catch(() => {
                console.error(`Failed to send ${member.user.tag} a message`)
            })
    }))
about 4 years ago · Juan Pablo Isaza Relatório

0

you can send a message to all users whose privacy settings are not turned on in this way

message.guild.members.cache.forEach(member => { // Looping through each member of the guild.
    // Trying to send a message to the member.
    // This method might fail because of the member's privacy settings, so we're using .catch
    member.send("Hello, this is my message!").catch(e => console.error(`Couldn't DM member ${member.user.tag}`));
});
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