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

214
Views
Discordjs DM todos los miembros del servidor

Estoy tratando de enviar mensajes directos a todos los miembros del servidor mediante un bot a través de un comando y solo envía mensajes directos a 4 personas que son administradores

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

0

Esta operación puede llevar mucho tiempo. La respuesta de @SuleymanCelik fue parcialmente correcta porque no todos los usuarios se almacenan en el caché de miembros del bot. Para obtener a todos los usuarios del servidor, debe realizar una llamada fetch() para todos los usuarios como este.

 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 Report

0

puede enviar un mensaje a todos los usuarios cuya configuración de privacidad no esté activada de esta manera

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