Discord.py: Unable to get members as a selfbot

Created on 1 Sep 2020  路  7Comments  路  Source: Rapptz/discord.py

Summary

Whenever I tried to get a list of all the members in the current server, it only returns around 30 - 150 items. This only happens in the bigger servers.
Note: I've only tried this on selfbot.

Reproduction Steps

Setup

import discord
from discord.ext import commands 

prefix = '>>'
client = commands.Bot(command_prefix=prefix, self_bot=True)

# code ...

client.run(token, bot=False)
  1. First way
@client.event
async def on_message(message):
    await client.process_commands(message)

@client.command()
async def list_members(ctx):
    print(ctx.guild.member_count)
    print(len(ctx.guild.members))
  1. Second way
@client.event
async def on_message(message):
    print(message.author.guild.member_count)
    print(len(message.author.guild.members))

Expected Results

If there are 5000 members in the server.

5000

Actual Results

If there are 5000 members in the server

32

Checklist

  • [x] I have searched the open issues for duplicates.
  • [x] I have shown the entire traceback, if possible.
  • [x] I have removed my token from display, if visible.

System Information


  • Python v3.8.5-final
  • discord.py v1.3.4-final
  • aiohttp v3.6.2
  • websockets v8.1
  • system info: Windows 10 10.0.18362

Most helpful comment

Discord does not dispatch the full member list to users anymore. Use a bot account with server members intents enabled.

All 7 comments

Discord does not dispatch the full member list to users anymore. Use a bot account with server members intents enabled.

@SebbyLaw I have the same question.can you tell me how to use server members intent?i can't find anything in docs

@SebbyLaw I have the same question.can you tell me how to use server members intent?i can't find anything in docs

https://blog.discord.com/the-future-of-bots-on-discord-4e6e050ab52e?gi=f32e9804962c
https://support.discord.com/hc/en-us/articles/360040720412
And it's on the Bot tab of your application

I know how to enable it.i was just thinking how the code is different than before in discord.py

It's not, the API either returns the result or it doesn't.

Hi, I don't know if it's related or not but I'm having also a different behavior on guild.members.

I tried the same simple script with 2 different version discord.py==1.3.4 and discord.py==1.5.0.

My dummy script to test it is the following one:

import discord

client = discord.Client()

@client.event
async def on_ready():
    print('We have logged in as {0.user}'.format(client))
    for m in client.guilds:
        print(m)
        print(m.members)

token = ".................."
client.run(token)

Ok now the results :

discord.py==1.3.4

[<Member id=1234 name='user1' discriminator='77]'....

I just sum up the result but it display the only server/guild on which I'm connected to and I get the list of all my users. It's the expected behavior.

discord.py==1.5.0

[<Member id=1235 name='mybotuser' discriminator='78]'....

In the list I have only one member. My bot itself.
In my output I can see I get the same server/guild name as well. But in this new version I don't have anymore others members listed.

@gaelL Your issue is caused by a lack of Intent subscription. As noted in the version 1.5 changelog "API Changes" section, you are required to pass the required Intents to your commands.Bot constructor to receive this information from the gateway.

This is not an issue with discord.py. For further help specific to using this library, you should join either the official discord.py server or the Discord API server, as the README recommends.

Was this page helpful?
0 / 5 - 0 ratings