Discord.py-如何仅向在线/ dnd / idle成员发送私人消息,而根本不发送?

时间:2020-06-25 04:39:37

标签: python python-3.x discord.py

我的代码就在那里:

x = ctx.guild.members == online
s = 0
for member in x:
    try:
        await member.send(embed=embed1)
        await member.send('|| https://discord.gg/y7EEXwU ||')
        print(f'{member.name} | {s}')
        s += 1
    except:
        pass

有人可以帮助我吗? 详细信息:代码经过了很好的汇总,以适合帖子模板。

1 个答案:

答案 0 :(得分:0)

您可以使用discord.Status作为过滤成员。 Link for discord.Status docs示例:

@client.event
async def on_ready():
    members = client.get_guild(GUILD_ID).members # all members
    # members with status online
    online_members = [member for member in members if member.status == discord.Status.online] 
    for member in online_members:
        try:
            await member.send("Hello")
        except:
            pass