-
Notifications
You must be signed in to change notification settings - Fork 6
/
discum-scraper(may-not-work).py
43 lines (39 loc) · 1.7 KB
/
discum-scraper(may-not-work).py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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['logger-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('guildid', 'channelid')
memberslist = []
with open("ids.json", "r") as file:
data = json.load(file)
for memberID in members:
if memberID not in data:
data.append(int(memberID))
print(memberID)
with open("ids.json", "w") as file:
json.dump(data, file)