-1

I want to create a command like - /announcement but I want to send message to every user of server in which bot is like:

Server a - will send

Server B - will send too by triggering one command, is this possible?

Ardent Coder
  • 3,777
  • 9
  • 27
  • 53
St533
  • 1
  • 2
  • 6
  • 2
    Please beware that sending unsolicited DMs to every user in every server your bot is in is against Discord's [Terms of Service](https://discord.com/terms), and can get you banned. – Pedro Fracassi May 07 '20 at 01:07
  • If an answer solves your question then please accept it to let others know it worked – Syntle May 09 '20 at 19:47

1 Answers1

1

You can use client.users to get all the users that have been cached then you can do the following:

client.users.cache.forEach(user => {
  user.send('hello')
})

Alternatively, you could loop through all your guilds using client.guilds and while looping through them, loop through their members and send them messages.

client.guilds.cache.forEach(guild => {
  guild.members.cache.forEach(member => {
    member.send('hello')
  })
})

Note: depending on the amount of users, this will take a long time to finish and will cause your bot to lag, along with the high chance of getting rate limited.

Syntle
  • 5,168
  • 3
  • 13
  • 34