0
votes

I am trying to generate a list of all of the members in a discord server using discord.py. Here is my code:

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

The problem is that I get only the Name of the Bot in the server but not any of the users, how to fix that?

1
There appears to be no error in the code. Are you sure that your bot is in a guild? - Nurqm
Yes I am sure prnt.sc/uz7odg - Abdo Sabry
im pretty sure the get_members_name function has to be async def and not just def - Remi_Zacharias
get_member_names doesn't use await or async for so making it async def is not required - unex

1 Answers

0
votes

A common reason for only seeing your bot in the members list is you haven't enabled privileged intents for your bot. Please see this page on enabling this for your bot.