Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

discord.py - Discord Bot - Guild Members Showing in count... but not in guild.members

having trouble getting my discord bot to list all the members of the only guild it's added to..

async def on_ready(self):
    print("logged in as {0}".format(self.user))
    
    guilds = self.guilds        
    print("guilds: " + str(guilds))

    guild = self.get_guild(my_guild_id)
    print("guild members: " + str(guild.members))

The interesting thing is that when i print out the guild itself it shows a member count of 5 (which is correct). However when instantiate the Guild object, and access the members property, it only shows the bot user itself as the member.

guild members: [<Member id=12345678 name='testapp1_bot' discriminator='0683' bot=True nick=None guild=<Guild id=12345 name="ethandrower's server" shard_id=None chunked=False member_count=5>>]
guilds: [<Guild id=12345 name="ethandrower's server" shard_id=None chunked=False member_count=5>]

I'm guessing this either my misunderstanding of the architecture of 'guilds' or a permissions on the bot thing. I've added the bot to the server with full administrator access, so I'm a little stumped as to why I can see the proper count of members, but not the Member objects themselves?

Any help would be greatly appreciated!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you're using the latest version of discord.py i.e. 1.5.0, you will need to enable Member intent and apply it to your bot.

How to enable Member Intent: https://discordpy.readthedocs.io/en/latest/intents.html#privileged-intents

Read More about Intents: https://discordpy.readthedocs.io/en/latest/intents.html


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...