使用 discord.py 获取不和谐服务器中所有成员的列表时出现问题

Posted

技术标签:

【中文标题】使用 discord.py 获取不和谐服务器中所有成员的列表时出现问题【英文标题】:Problem when getting list of all members in a discord server with discord.py 【发布时间】:2020-11-27 19:38:54 【问题描述】:

我正在尝试使用 discord.py 生成不和谐服务器中所有成员的列表。这是我的代码:

import discord

client = discord.Client()
@client.event
async def on_ready():
    people = set(client.get_all_members())
    print(people)

client.run("not about to show u my token lol")

然而,结果不仅仅是每个成员的名字,还有用户ID、公会信息和一堆其他东西。我怎么能把它缩小到只有不和谐服务器中的人的名字。

【问题讨论】:

【参考方案1】:

尝试像这样使用member.name

import discord


def get_member_names():
    for guild in client.guilds:
        for member in guild.members:
            yield member.name


client = discord.Client()
@client.event
async def on_ready():
    people = set(get_member_names())
    print(people)

client.run("not about to show u my token lol")

【讨论】:

以上是关于使用 discord.py 获取不和谐服务器中所有成员的列表时出现问题的主要内容,如果未能解决你的问题,请参考以下文章