Discord Bot reveals only its own identity, missing other guild members

Despite following a tutorial and having admin rights, my Discord bot shows only its name, ignoring the five other guild users. See this example:

import discord
import os

bot_key = os.getenv('BOT_KEY')
client = discord.Client()

@client.event
async def on_connect():
    for server in client.guilds:
        print(server, [user.display_name for user in server.members])

client.run(bot_key)

hey, i had this before. i re-enabled the members intent and updated discord.py. a full restart helped too. sometimes discord caches things so wait a bit after changes. might b a pesky cache issue.

In my experience, similar behavior was observed when the bot was not properly configured to request full member data. I solved this issue by double-checking that the members intent was enabled on both the Discord Developer Portal and within the code. Upgrading to a recent version of discord.py helped, as this version handles intents more strictly. Also, I added explicit declaration of the members intent during client initialization. This adjustment allowed the bot to retrieve all server members accurately. Additionally, verifying that the permissions granted in the server settings were sufficient was a key step in resolving the issue.

I encountered a similar issue earlier while working on my Discord bot. After some testing, I found that besides enabling the members intent on the developer portal, it is essential to update the code to properly declare the intent when initializing the client. In my case, switching to a client with explicit intents and confirming the library version resolved the issue. I recommend reviewing your code to ensure your client is set up with the necessary intents and verifying that your discord.py version fully supports them.

After experimenting with similar issues, I discovered that switching from the on_connect event to the on_ready event helped me obtain the full list of guild members. The on_connect event seems to trigger before the member cache is fully populated, which can lead to missing data. Besides ensuring that the members intent is enabled, I also found that explicitly fetching fresh guild data—for example, using a proper delay or directly invoking a fetch—can resolve these issues. Double-checking the bot’s permissions in the invite URL also makes sure it has the required access to all member data.

hey, check if u enabled members intent in both code and bot settings; i had similar issues and turnning that on solved it. might be the missing part or something with your permissions.