在Discord.py中获取公会的所有成员

2024-05-19 00:03:12 发布

您现在位置:Python中文网/ 问答频道 /正文

嘿,这是我下面的代码,它可以工作,但我只得到与我聊天(私下聊天)一次的用户


@client.command()
async def hi(ctx):
    with open('users.txt','w') as f:
        for member in ctx.guild.members:
            print("{},{}".format(member,member.id), file=f,)
        print("done")


Tags: 代码用户txtclientasyncdefwithopen
2条回答

您可能需要调用^{}从Discord API更新客户端内部缓存:

@client.command()
async def hi(ctx):
    with open('users.txt','w') as f:
        async for member in ctx.guild.fetch_members(limit=None):
            print("{},{}".format(member,member.id), file=f,)
    print("done")

您是否启用了意图,如果没有,请启用它们并重试

相关问题 更多 >

    热门问题