在Discord.py中从公会获取所有成员 [英] Get All Members from a Guild in Discord.py

查看:90
本文介绍了在Discord.py中从公会获取所有成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,这是我的以下代码,它可以正常工作,但是我只获得了一次与我聊天(在私人聊天中)的用户。

Hey this is my following code and it works, but I only get the users with whom I chatted(in private chat) once.


@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")


推荐答案

您可能需要致电 fetch_members 来更新来自Discord API的客户端内部缓存:

You might need to call fetch_members to update the clients internal cache from the 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")

这篇关于在Discord.py中从公会获取所有成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆