user15238078
user15238078

Reputation:

Send a DM to all the members of a server discord.py

I'm trying to send a dm to all the members of a server. The code I'm using gives no errors but it isn't working.

@bot.command(pass_context=True)
async def dm(ctx, *, message):
        for user in ctx.guild.members:
            try:
                await user.send(message)
                print(f"Sent {user.name} a DM.")
            except:
                print(f"Couldn't DM {user.name}.")
        print("Sent all the server a DM.")

Upvotes: 0

Views: 1951

Answers (1)

supg
supg

Reputation: 31

I know this is already answered but to anyone looking at this in the future:

  • Make sure your bot's intents allow it to access members
  • Also keep in mind some members have DMs turned off (dms from server members)

hope this helps even a little

Upvotes: 1

Related Questions