How to DM everyone with a bot - discord.py

别说谁变了你拦得住时间么 提交于 2019-12-09 12:36:01

问题


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)

回答1:


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)


来源:https://stackoverflow.com/questions/45785727/how-to-dm-everyone-with-a-bot-discord-py

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!