Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

python - Discord Selfbot cant get all members, just part of it

Hey i am trying to get all the users in a specific guide, and i am getting part of the users and not all of them, why?, And i dont care about discord terms, i am not gonna spam servers or something like this so please help instead telling me the discord rules because i am know it well, This is the code i did,

import discord
import asyncio

intents = discord.Intents(messages=True, guilds=True, members=True)

client = discord.Client(intents=intents)


token = ""



@client.event
async def on_ready():
    print("Bot Is Ready!")
    guild = client.get_guild(328154277111398403)
    for member in guild.members:
        print(member)
        await asyncio.sleep(0.1)




client.run(token, bot=False)
See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

in the context of selfbots/userbots, discord.py doesn't actually have the ability to get the member list (or, at least, a significant portion of it), and therefore is not suited for this task. Instead, you'll either have to use a different library or code your own solution. Keep on reading for some code :)

Code:
A python lib with this support is discum.
Here's the least amount of code required to get the member list with discum:

import discum
bot = discum.Client(token='blah blah blah')

@bot.gateway.command
def helloworld(resp):
    if resp.event.ready_supplemental: 
        bot.gateway.fetchMembers("GUILD_ID_HERE", "CHANNEL_ID_HERE")

bot.gateway.run()

And here's another example that creates a function called get_members that returns the member list: https://github.com/Merubokkusu/Discord-S.C.U.M/blob/master/examples/gettingGuildMembers.py

And here are more examples: https://github.com/Merubokkusu/Discord-S.C.U.M/blob/master/docs/fetchingGuildMembers.md

How does it work?
Since we can't request for the member list the same way bot accounts can, we instead need to exploit the member list (yea, that members sidebar on the right that you see when going to a guild). We need to read that entire thing, piece by piece.

Essentially how it's done is the client first subscribes to member events in a channel in a guild (Luna somewhat went over this in her unofficial discord docs, but left out a lot). Then, as the user scrolls through the member list, more lazy requests are sent to get each chunk of the member list. And this is what happens in discum: lazy requests are sent until the entire member list is fetched. Here's some more info.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...