【问题标题】:Discord member scraperDiscord 成员刮刀
【发布时间】:2022-01-25 02:53:06
【问题描述】:

这个脚本抓取服务器中的所有成员 ID,然后将 ID 保存在 ids.json 中,我想让它在抓取特定数量的成员 ID 后保存 ID。因此,例如,我希望它只抓取 100 个用户 ID,然后保存它,或者让它只抓取在线用户 ID。我该怎么办?

start = time.time()
import sys
import subprocess
# python -m pip install --user --upgrade git+https://github.com/Merubokkusu/Discord-S.C.U.M#egg=discum
try:
  import discum
except ImportError:
  try:
      subprocess.check_call([sys.executable, "-m", "pip", "install", '--user', "--upgrade",
                             "git+https://github.com/Merubokkusu/Discord-S.C.U.M#egg=discum"])
  except:
      subprocess.check_call([sys.executable, "-m", "pip", "install", 'discum'])

import os
import json
with open('config.json') as f:
    yamete_kudasai = json.load(f)
token = yamete_kudasai['token']
bot = discum.Client(token=token)

def close_after_fetching(resp, guild_id):
    if bot.gateway.finishedMemberFetching(guild_id):
        lenmembersfetched = len(bot.gateway.session.guild(guild_id).members) #this line is optional
        print(str(lenmembersfetched)+' members fetched') #this line is optional
        bot.gateway.removeCommand({'function': close_after_fetching, 'params': {'guild_id': guild_id}})
        bot.gateway.close()

def get_members(guild_id, channel_id):
    bot.gateway.fetchMembers(guild_id, channel_id, keep="all", wait=1) #get all user attributes, wait 1 second between requests
    bot.gateway.command({'function': close_after_fetching, 'params': {'guild_id': guild_id}})
    bot.gateway.run()
    bot.gateway.resetSession() #saves 10 seconds when gateway is run again
    return bot.gateway.session.guild(guild_id).members

members = get_members('878417405217472572', '878417406140223592')
memberslist = []
with open("ids.json", "r") as file:
  data = json.load(file)
total_scraped = 0
for memberID in members:
  if memberID not in data:
    total_scraped += 1
    data.append(int(memberID))
    print(f"{total_scraped}/{len(members)} - {memberID}")
with open("ids.json", "w") as file:
  json.dump(data, file)
end = time.time()
print(f"Scraped {total_scraped} User IDs successfully\nTime Taken: {end - start}s")```

【问题讨论】:

    标签: python json


    【解决方案1】:

    我很确定 discord TOS 不允许这样做,因为不允许您通过客户端运行脚本。如果您将它作为机器人运行,它将是:

    import json
    import discord
    from discord.ext import commands
    
    
    
    @commands.command()
    async def get_ids(ctx):
        with open("folder/userdata.json", 'r') as f:
            users = json.load(f) # Opens json file
    
        for members in ctx.guild.members:
            id = members.id
            users["userid"] = {"ID":id}
            print(f"ID: {id} has been saved to json file")
    
        with open("folder/userdata.json", "w") as f:
            json.dump(users, f, indent=4)
    

    【讨论】:

      【解决方案2】:

      这是一个可能有帮助的程序

      https://github.com/Tyrrrz/DiscordChatExporter

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-08-31
        • 2017-07-18
        • 2021-10-19
        • 1970-01-01
        • 1970-01-01
        • 2019-04-16
        • 2018-08-19
        相关资源
        最近更新 更多