如何使用discord.py列出Discord服务器中的成员列表?

时间:2020-10-14 13:10:23

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

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

import discord
from discord.ext import commands


class Events(commands.Cog):
    def __init__(self, client):
        self.client = client

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

    @commands.Cog.listener()
    async def on_ready(self):
        await self.client.change_presence(activity=discord.Activity(type=discord.ActivityType.watching,
                                                                    name="the Chat."))
        print('Bot has logged in as {0.user.name}'.format(self.client))

        people = set(self.get_member_names())
        print(people)

def setup(client):
    client.add_cog(Events(client))

问题是我只在服务器中得到Bot的名称,而没有任何用户,如何解决?

1 个答案:

答案 0 :(得分:0)

仅在成员列表中看到您的漫游器的常见原因是您尚未为漫游器启用特权意图。请参阅this page,了解如何为您的机器人启用此功能。