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

230
Vistas
dm all command discord js

i want the command to dm 1 member then wait 5 seconds then dm the next member untill all members are dm by the bot

this is the code i have

if (command === 'dmall') {
  message.guild.members.cache.forEach(async (member) => {
    const messageSent = await member.send(args[0]);
    console.log(messageSent);
    await wait(5000);
  });
}

the error i get is member.send is not function

this is the wait thing it has no problems

let wait = (ms) => {
  if (!ms) throw new TypeError("Time isn't specified");
  return new Promise((resolve) => setTimeout(resolve, ms));
};
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Your code is working for me. So the problem is not in your code that you give probably.

You must add GUILD_MEMBERS intent to your client in order to read all the guild member user data.

You should replace your code with this when creating a new client instances :

const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MEMBERS] });

( Or if you have another intents, just add Intents.FLAGS.GUILD_MEMBERS to it. )

Note : This intent is privilaged. Which means if you add this intents to your bot, it will not be able to join any guild anymore after 100 guild reached until your bot verified. If this is a private bot. Then it would be fine.

Also make sure to catch an error in your code when you send a message to all member to prevent your bot to crashing when :

  • A user disabling 'Allow direct message from server member'
  • A user is a bot. It's impossible to DM a bot.

So it should be :

if (command === 'dmall') {
  message.guild.members.cache.forEach(async (member) => {
    const messageSent = await member.send(args[0])
    .catch(err => {console.log(err)});
    console.log(messageSent);
    await wait(5000);
  });
}

Tell me if its works or not.

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