0

I wanna dm everyone who has the dmme role using on_ready (dm updates system) But i can't get it to work. I know that this code is outdated, but i've never done anything like this before and I don't know how to.

@bot.event
async def on_ready(ctx, member : discord.Member = None, *, message = "test"):
    print("ready")
    if member == "@dmme":
        for server_member in ctx.message.server.members:
            await bot.send_message(server_member, message)

How to DM everyone with a bot - discord.py

How to DM everyone in a Discord server with discord.py?

Also..how can i make it only select x users with the role and dm only them (insider program with random testing selection)

1 Answers1

3
@bot.event
async def on_ready():
    for guild in bot.guilds:  # all servers of the bot
        role = discord.utils.find(lambda r: r.name == 'dmme ', guild.roles)
        for member in guild.members:
            if role in member.roles:
                await member.send("WHAT_YOU_WANT_TO_SAY")

But:

  1. Make sure you enable intents for that.
  2. Itβ€˜s not a good idea to dm many people at the same time because of a limit for that from discord. So think twice if you really want to do that. (My bot got blocked for one hour because of similar stuff)
Abdulaziz
  • 3,363
  • 1
  • 7
  • 24
bad_coder
  • 201
  • 1
  • 9
  • Given the second warning I realised that I 100% need the random selection of a given number of users.. There isn't really a way to do that, right ? – Mihai Cristian May 22 '21 at 13:47
  • `guild.members` is a list. So you could use the `random` module with its `random.choices()` method in order to select a random amount of people. – bad_coder May 22 '21 at 15:18
  • what if you have a random timeout after each message? do you still hit the limits?like a sleep 10 added insdie your for loop – PirateApp Jul 28 '23 at 13:29