Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

235
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!