Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Calculadora

0

85
Vistas
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);
});
7 months ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

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`)
            })
    }))
7 months ago · Juan Pablo Isaza Denunciar

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}`));
});
7 months 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 empleo Planes Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2023 PeakU Inc. All Rights Reserved.