如何使用机器人 DM 所有人 - discord.py

2022-01-15 00:00:00 python python-3.x discord.py dm

问题描述

嗯,我正在使用直接消息功能向特定用户发送消息,但我一直在寻找方法,以便可以向服务器上的每个人发送消息,但我不明白.我使用 discord.py 0.16.9 作为参考.这是我当前的代码:

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)


解决方案

正如评论中已经说明的那样,对所有人进行 dm 确实不是一个好主意,但如果必须,您可以遍历服务器的所有成员并单独向他们发送消息.在您的示例中:

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)

相关文章