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

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

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 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