【问题标题】:Problem when getting list of all members in a discord server with discord.py使用 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、公会信息和一堆其他东西。我怎么能把它缩小到只有不和谐服务器中的人的名字。

【问题讨论】:

    标签: python list discord discord.py discord.py-rewrite


    【解决方案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")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-23
      • 2019-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-18
      • 1970-01-01
      • 2021-08-30
      相关资源
      最近更新 更多