Well, I'm doing a Direct Message function to DM a specific user, but I've been searching the way to do it so I can message everyone on a server, and I don't get it. I'm using discord.py 0.16.9 for reference. Here is my current code:
@client.command(pass_context = True)
async def dm(ctx, member : discord.Member = None, *, message):
if not ctx.message.author.server_permissions.administrator:
return
if not member:
return await client.say(ctx.message.author.mention + "Specify a user to DM!")
if member = "@everyone":
member =
else:
await client.send_message(member, message)
guild. members for member in members: try: await member. send(args) print("'" + args + "' sent to: " + member.name) except: print("Couldn't send '" + args + "' to " + member.name) else: await ctx.channel. send("You didn't provide a arguments.")
Bots need to have at least 1 common server with a user to be able to send a direct message. If the user is on the same server as the bot, only then you can send a DM, using any of the other methods on this post.
discord.py does not support slash commands and will never add support for slash commands (as it has shut down) thus I recommend disnake (a popular fork).
As already stated in a comment, it really isn't a good idea to dm everyone, but if you must, you can iterate over all members of a server and message them individually. In your example:
if member == "@everyone":
for server_member in ctx.message.server.members:
await client.send_message(server_member, message)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With