# Keep in mind that there's no actual api endpoint for users to get guild members. | |
# So, to get guild members, we have to request for and read the member list. | |
# This is all handled with the bot.gateway.fetchMembers(...) function :) . This function can either be run while the gateway is connected or before the gateway connects. | |
# Note, you'll need to connect to the gateway to get the member list. | |
# An example usage is below. The Guild and Channel ids used are from the fortnite server (652k members, around 150k of those are actually fetchable). | |
# The number of fetchable members changes from time to time. | |
# https://github.com/Merubokkusu/Discord-S.C.U.M/blob/master/docs/using/Gateway_Actions.md#gatewayfetchmembers | |
import discum | |
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('serverid', 'channelid') | |
memberslist = [] | |
for memberID in members: | |
memberslist.append(memberID) | |
print(memberID) | |
f = open('users.txt', "a") | |
for element in memberslist: | |
f.write(element + '\n') | |
f.close() |
Could not retrieve Discord's build number it says.
And this at the end:
"Traceback (most recent call last):
File "C:\Users\Abidcomputers\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\models.py", line 910, in json
return complexjson.loads(self.text, **kwargs)
File "C:\Users\Abidcomputers\AppData\Local\Programs\Python\Python310\lib\json_init_.py", line 346, in loads
return _default_decoder.decode(s)
File "C:\Users\Abidcomputers\AppData\Local\Programs\Python\Python310\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users\Abidcomputers\AppData\Local\Programs\Python\Python310\lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\Users\Abidcomputers\Desktop\massdms\scrape.py", line 2, in
bot = discum.Client(token='NjQ5MjUzNjA2ODAxMDE0Nzg1.Ykan-A.t8gsk-2i0ZfaK2oLEIubxnRa4dk')
File "C:\Users\Abidcomputers\AppData\Local\Programs\Python\Python310\lib\site-packages\discum\discum.py", line 104, in init
self.__xfingerprint = self.getXFingerprint(generateIfNone=True)
File "C:\Users\Abidcomputers\AppData\Local\Programs\Python\Python310\lib\site-packages\discum\discum.py", line 216, in getXFingerprint
return imports.Login(self.s, self.discord, self.log).getXFingerprint(generateIfNone)
File "C:\Users\Abidcomputers\AppData\Local\Programs\Python\Python310\lib\site-packages\discum\start\login.py", line 38, in getXFingerprint
xfingerprint = reqxfinger.json().get('fingerprint')
File "C:\Users\Abidcomputers\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\models.py", line 917, in json
raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: [Errno Expecting value]"
C:\Users\white\Desktop\음악봇\meber>python scrape.py
Retrieving Discord's build number...
Could not retrieve discord build number.
invalid literal for int() with base 10: 'ull!=='
[+] (<discum.start.login.Login->getXFingerprint) Get -> https://discord.com/api/v9/experiments
[+] (<discum.start.login.Login->getXFingerprint) Response <- b'{"fingerprint": "969583720891834498.9xHQPAhmyAz8gzJpZ8qskaxL2Zk", "assignments": [[70411085, 0, 1, -1, 0], [16416918, 0, 1, -1, 0], [3816091942, 3, 0, -1, 0], [4130837190, 0, 10, -1, 0], [852550504, 3, 1, -1, 0], [2599708267, 0, 1, -1, 0], [1365487849, 6, 1, -1, 0], [3128009767, 0, 10, -1, 0], [2973729510, 2, 1, -1, 0], [2571931329, 1, 6, -1, 0], [1260103069, 0, 1, -1, 0], [2003494159, 1, 1, -1, 0], [2458926251, 1, 6, -1, 2], [4027800, 1, 6, -1, 3], [51193042, 0, 1, -1, 0], [2063302207, 1, 1, -1, 0], [2634540382, 3, 1, -1, 0], [427713714, 0, 1, -1, 0], [3388129398, 0, 1, -1, 0], [3316720711, 0, 1, -1, 0], [156590431, 0, 1, -1, 2], [1126477623, 0, 1, -1, 0], [2617218444, 4, 1, -1, 2], [3615263239, 0, 1, -1, 0], [414823706, 0, 1, -1, 0], [3035674767, 0, 1, -1, 0], [261678880, 0, 1, -1, 0], [1758928808, 2, 1, -1, 0], [144783748, 0, 1, -1, 0], [2311413706, 0, 1, -1, 0], [1304635016, 0, 1, -1, 0], [2031154483, 0, 1, -1, 0], [1609782151, 0, 1, -1, 2], [1047093347, 0, 1, -1, 2], [3354177721, 0, 1, -1, 0], [3643362751, 0, 1, -1, 0], [698017395, 0, 1, -1, 0], [902020832, 3, 3, -1, 1], [1503481915, 0, 1, -1, 2], [3346844407, 0, 1, -1, 0], [3753034466, 1, 2, -1, 0], [881221695, 1, 1, -1, 0], [105505141, 1, 1, -1, 1], [3921541483, 2, 1, -1, 0], [3125584553, 1, 1, -1, 0], [219203323, 1, 1, -1, 0], [2854861606, 0, 1, -1, 1], [203190011, 0, 1, -1, 0], [2416791266, 1, 1, -1, 0], [1740882580, 1, 1, -1, 0], [3526033165, 0, 1, -1, 0], [3699939463, 0, 1, -1, 2], [1913882179, 0, 1, -1, 2], [3884403666, 1, 1, -1, 0], [949804751, 3, 1, -1, 0], [2365882538, 1, 1, -1, 0], [2780619238, 1, 0, -1, 0], [2839301427, 1, 1, -1, 0], [2740541143, 1, 0, -1, 0], [1567199723, 0, 1, -1, 1], [2237617796, 0, 1, -1, 0], [2804024497, 0, 1, -1, 2], [2481496956, 0, 1, -1, 0], [1305004983, 0, 1, -1, 0], [4196771574, 6, 6, -1, 0], [3121542871, 1, 0, -1, 0], [934741861, 2, 1, -1, 1], [2639499196, 3, 1, -1, 1], [1926403380, 0, 1, -1, 0], [1175582167, 1, 1, -1, 0], [2012365622, 0, 1, -1, 0], [3615787841, 0, 1, -1, 0], [1369422507, 0, 1, -1, 0], [4257117014, 1, 2, -1, 0], [2191591221, 0, 1, -1, 0], [1860870966, 0, 1, -1, 0], [613690816, 2, 1, -1, 0], [754424255, 0, 0, -1, 0], [282861292, 0, 0, -1, 0], [2950595281, 2, 1, -1, 0], [4263969313, 2, 1, -1, 2], [2496945544, 0, 1, -1, 0], [3662016164, 3, 2, -1, 0], [2486607747, 0, 1, -1, 0], [604497254, 0, 1, -1, 0], [2736193736, 0, 1, -1, 0], [1138665623, 0, 1, -1, 0], [3542498455, 0, 1, -1, 0], [723256323, 0, 1, -1, 0], [3805175685, 0, 1, -1, 0], [3866818837, 0, 1, -1, 0], [3450899088, 1, 1, -1, 0], [3656796460, 0, 1, -1, 0], [334012295, 0, 1, -1, 0], [1685515200, 0, 7, -1, 0], [1748842958, 1, 1, -1, 0], [899439768, 1, 1, -1, 0], [4100056516, 0, 1, -1, 3], [3047034364, 0, 1, -1, 0], [799757083, 0, 3, -1, 0], [854704408, 0, 1, -1, 0], [1308053712, 0, 1, -1, 0], [1363066938, 3, 1, -1, 1], [1814483290, 0, 1, -1, 0], [3074844387, 0, 1, -1, 0], [2855612301, 0, 1, -1, 0], [4084522269, 0, 1, -1, 0], [1613012371, 0, 1, -1, 0], [3567821600, 0, 0, -1, 1], [3557480712, 0, 1, -1, 0], [3606428003, 0, 1, -1, 0], [2815803943, 0, 0, -1, 0], [3889077804, 2, 1, -1, 0], [4079214319, 2, 1, -1, 0], [2447247632, 4, 0, -1, 0], [1621989768, 0, 0, -1, 0], [191312409, 2, 1, -1, 0]]}'
[gateway] Connected to websocket.
[gateway] > {'op': 2, 'd': {'token': 'OTM1Njk2Nzk0ODMzMjU2NTA5.YmvVSA.fxHQwg96slZZYIA3WMsOwj7Ix70', 'capabilities': 253, 'properties': {'os': 'Windows', 'browser': 'Chrome', 'device': '', 'system_locale': 'en-US', 'browser_user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36', 'browser_version': '96.0.4664', 'os_version': '10', 'referrer': '', 'referring_domain': '', 'referrer_current': '', 'referring_domain_current': '', 'release_channel': 'stable', 'client_build_number': 107767, 'client_event_source': None}, 'presence': {'status': 'online', 'since': 0, 'activities': [], 'afk': False}, 'compress': False, 'client_state': {'guild_hashes': {}, 'highest_last_message_id': '0', 'read_state_version': 0, 'user_guild_settings_version': -1}}}
[gateway] < {'t': None, 's': None, 'op': 10, 'd': {'heartbeat_interval': 41250, 'trace': ['["gateway-prd-main-z5fg",{"micros":0.0}]']}}
[gateway] entering heartbeat
[gateway] < {'t': 'READY', 's': 1, 'op': 0, 'd': {'v': 9, 'users': [{'username': 'MEE6', 'public_flags': 65536, 'id': '159985870458322944', 'discriminator': '4876', 'bot': True, 'avatar_decoration': None, 'avatar': 'b50adff099924dd5e6b72d13f77eb9d7'}, {'username': 'Talseng', 'public_flags': 256, 'id': '425246853555027978', 'discriminator': '0001', 'avatar': '65953a6639c415ea849d85cd38bb5169'}, {'username': 'AlphqNyang', 'public_flags': 64, 'id': '503160271301246976', 'discriminator': '9762', 'avatar': None}, {'username': 'betq', 'public_flags': 64, 'id': '615880272591978506', 'discriminator': '4465', 'avatar': 'e61acea859551b4fb06e59c20beca3ce'}, {'username': '시원한냉장고', 'id': '801661916275539969', 'discriminator': '5797', 'avatar': None}, {'username': 'ryder2585라이더', 'public_flags': 0, 'id': '857940869452791818', 'discriminator': '1673', 'avatar_decoration': None, 'avatar': 'b705f2c88300f272af865405176a79b8'}, {'username': '솔이', 'public_flags': 0, 'id': '861135193398444082', 'discriminator': '4916', 'avatar_decoration': None, 'avatar': 'f87560bc68280fcdb4e7688ce9182aea'}, {'username': 'qstep12', 'id': '935696794833256509', 'discriminator': '5064', 'avatar': None}, {'username': '이벤트 알람
[gateway] < {'t': 'READY_SUPPLEMENTAL', 's': 2, 'op': 0, 'd': {'merged_presences': {'guilds': [[{'user_id': '615880272591978506', 'status': 'dnd', 'client_status': {'desktop': 'dnd'}, 'activities': [{'type': 0, 'timestamps': {'start': 1651236851000}, 'state': '게임 중', 'name': 'League of Legends', 'id': 'f3c9b8eedd1ce9cb', 'details': '소환사의 협곡 (일반)', 'created_at': 1651236847455, 'assets': {'large_text': '케인', 'large_image': '403244947891027978'}, 'application_id': '401518684763586560'}]}, {'user_id': '159985870458322944', 'status': 'online', 'client_status': {'web': 'online'}, 'activities': []}], [{'user_id': '159985870458322944', 'status': 'online', 'client_status': {'web': 'online'}, 'activities': []}], [], [{'user_id': '615880272591978506', 'status': 'dnd', 'client_status': {'desktop': 'dnd'}, 'activities': [{'type': 0, 'timestamps': {'start': 1651236851000}, 'state': '게임 중', 'name': 'League of Legends', 'id': 'f3c9b8eedd1ce9cb', 'details': '소환사의 협곡 (일반)', 'created_at': 1651236847455, 'assets': {'large_text': '케인', 'large_image': '403244947891027978'}, 'application_id': '401518684763586560'}]}], [], []], 'friends': []}, 'merged_members': [[{'user_id': '801661916275539969', 'roles': ['923498655921627166'], 'mute': False, 'joined_at': '2022-04-08T10:59:20.648000+00:00', 'hoisted_role': '923498655921627166', 'flags': 0, 'deaf': False}, {'user_id': '425246853555027978', 'roles': ['923498655921627166', '714675869397942422', '773533117234544670'], 'premium_since': '2022-04-02T12:53:42.650000+00:00', 'pending': False, 'nick': None, 'mute': False, 'joined_at': '2021-09-26T13:57:22.097000+00:00', 'hoisted_role': '714675869397942422', 'flags': 0, 'deaf': False, 'communication_disabled_until': None, 'avatar': 'a_af3d071b92d231d46682f1bee6100187'}, {'user_id': '801661916275539969', 'roles': ['923498655921627166'], 'mute': False, 'joined_at': '2022-04-08T10:59:20.648000+00:00', 'hoisted_role': '923498655921627166', 'flags': 0, 'deaf': False}, {'user_id': '425246853555027978', 'roles': ['923498655921627166', '714675869397942422', '773533117234544670'], 'premium_since': '2022-04-02T12:53:42.650000+00:00', 'pending': False, 'nick': None, 'mute': False, 'joined_at': '2021-09-26T13:57:22.097000+00:00', 'hoisted_role': '714675869397942422', 'flags': 0, 'deaf': False, 'communication_disabled_until': None, 'avatar': 'a_af3d071b92d231d46682f1bee6100187'}, {'user_id': '615880272591978506', 'roles': ['923498655921627166'], 'mute': False, 'joined_at': '2022-04-02T10:17:18.261000+00:00', 'hoisted_role': '923498655921627166', 'flags': 0, 'deaf': False}, {'user_id': '159985870458322944', 'roles': ['959722221889277993', '958313561032126467'], 'mute': False, 'joined_at': '2022-03-29T10:35:57.624000+00:00', 'hoisted_role': None, 'flags': 0, 'deaf': False}], [{'user_id': '857940869452791818', 'roles': ['930810900145918055'], 'mute': False, 'joined_at': '2021-12-23T12:37:26.988000+00:00', 'hoisted_role': None, 'flags': 0, 'deaf': False}, {'user_id': '159985870458322944', 'roles': ['926285617908809749'], 'mute': False, 'joined_at': '2021-12-31T01:28:20.919000+00:00', 'hoisted_role': None, 'flags': 0, 'deaf': False}], [{'user_id': '961620436737744906', 'roles': ['968392944732233731'], 'premium_since': None, 'pending': False, 'nick': None, 'mute': False, 'joined_at': '2022-04-26T06:07:49.959322+00:00', 'hoisted_role': None, 'flags': 0, 'deaf': False, 'communication_disabled_until': None, 'avatar': None}, {'user_id': '857940869452791818', 'roles': [], 'mute': False, 'joined_at': '2022-02-15T04:59:11.176000+00:00', 'hoisted_role': None, 'flags': 0, 'deaf': False}], [{'user_id': '857940869452791818', 'roles': [], 'mute': False, 'joined_at': '2022-03-27T11:28:01.468000+00:00', 'hoisted_role': None, 'flags': 0, 'deaf': False}, {'user_id': '615880272591978506', 'roles': [], 'mute': False, 'joined_at': '2022-03-29T08:17:16.076000+00:00', 'hoisted_role': None, 'flags': 0, 'deaf': False}, {'user_id': '503160271301246976', 'roles': [], 'mute': False, 'joined_at': '2022-04-22T04:59:31.515000+00:00', 'hoisted_role': None, 'flags': 0, 'deaf': False}], [{'user_id': '857940869452791818', 'roles': ['965594703527550976', '965583804976750612'], 'premium_since': None, 'pending': False, 'nick': None, 'mute': False, 'joined_at': '2022-04-18T11:31:10.910000+00:00', 'hoisted_role': '965583804976750612', 'flags': 0, 'deaf': False, 'communication_disabled_until': None, 'avatar': None}], []], 'guilds': [{'voice_states': [{'user_id': '425246853555027978', 'suppress': False, 'session_id': 'ce472f670575f6c731f18f68925af0d6', 'self_video': False, 'self_stream': True, 'self_mute': True, 'self_deaf': False, 'request_to_speak_timestamp': None, 'mute': False, 'deaf': False, 'channel_id': '959816092203769896'}, {'user_id': '801661916275539969', 'suppress': False, 'session_id': '2cc0b1a66600e302a91c66ab06b60d9f', 'self_video': False, 'self_mute': True, 'self_deaf': False, 'request_to_speak_timestamp': None, 'mute': False, 'deaf': False, 'channel_id': '959816092203769896'}], 'id': '712928394899226626', 'embedded_activities': []}, {'voice_states': [], 'id': '923554899994767410', 'embedded_activities': []}, {'voice_states': [], 'id': '943008518921912341', 'embedded_activities': []}, {'voice_states': [], 'id': '957601887895584778', 'embedded_activities': []}, {'voice_states': [], 'id': '965575215516102736', 'embedded_activities': []}, {'voice_states': [], 'id': '968125429976301588', 'embedded_activities': []}]}}
Exception ignored in thread started by: <bound method GatewayServer._response_loop of <discum.gateway.gateway.GatewayServer object at 0x000001AC999E6E80>>
Traceback (most recent call last):
File "C:\Users\white\AppData\Local\Programs\Python\Python38\lib\site-packages\discum\gateway\gateway.py", line 300, in _response_loop
function(resp, **params)
File "C:\Users\white\AppData\Local\Programs\Python\Python38\lib\site-packages\discum\gateway\guild\combo.py", line 71, in fetchMembers
self.gatewayobj.session.guild(guild_id).resetMembers() #reset
File "C:\Users\white\AppData\Local\Programs\Python\Python38\lib\site-packages\discum\gateway\session.py", line 246, in resetMembers
Session.settings_ready['guilds'][self.guildID]['members'] = {}
KeyError: '964831443316527154'
[gateway] < {'t': 'MESSAGE_CREATE', 's': 3, 'op': 0, 'd': {'type': 0, 'tts': False, 'timestamp': '2022-04-29T12:59:36.393000+00:00', 'referenced_message': None, 'pinned': False, 'nonce': '969583734116319232', 'mentions': [], 'mention_roles': [], 'mention_everyone': False, 'member': {'roles': ['923498655921627166'], 'mute': False, 'joined_at': '2022-04-08T09:07:11.732000+00:00', 'hoisted_role': '923498655921627166', 'flags': 0, 'deaf': False}, 'id': '969583734892404746', 'flags': 0, 'embeds': [], 'edited_timestamp': None, 'content': '요즘 정보력 ㄷㄷ하네', 'components': [], 'channel_id': '762969306967048214', 'author': {'username': 'RaDiaN', 'public_flags': 0, 'id': '706372689413013526', 'discriminator': '2152', 'avatar_decoration': None, 'avatar': 'ffa556a1c90ea69e6027f1f5d5053011'}, 'attachments': [], 'guild_id': '712928394899226626'}}
Exception ignored in thread started by: <bound method GatewayServer._response_loop of <discum.gateway.gateway.GatewayServer object at 0x000001AC999E6E80>>
Traceback (most recent call last):
File "C:\Users\white\AppData\Local\Programs\Python\Python38\lib\site-packages\discum\gateway\gateway.py", line 300, in _response_loop
function(resp, **params)
File "C:\Users\white\AppData\Local\Programs\Python\Python38\lib\site-packages\discum\gateway\guild\combo.py", line 89, in fetchMembers
ranges = self.getRanges(index, multiplier, self.gatewayobj.session.guild(guild_id).memberCount) if not endFetching else [[0],[0]]
File "C:\Users\white\AppData\Local\Programs\Python\Python38\lib\site-packages\discum\gateway\session.py", line 376, in memberCount
return Session.settings_ready['guilds'][self.guildID]['member_count']
KeyError: '964831443316527154
what is this error
<bound method GatewayServer._response_loop of <discum.gateway.gateway.GatewayServer object at 0x0000019848F755A0>>
Traceback (most recent call last):
File "C:\Users\Abdo\AppData\Local\Programs\Python\Python311\Lib\site-packages\discum-1.4.1-py3.11.egg\discum\gateway\gateway.py", line 303, in _response_loop
function(resp, **params)
File "C:\Users\Abdo\AppData\Local\Programs\Python\Python311\Lib\site-packages\discum-1.4.1-py3.11.egg\discum\gateway\guild\combo.py", line 70, in fetchMembers
if not self.gatewayobj.session.guild(guild_id).hasMembers and reset:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Abdo\AppData\Local\Programs\Python\Python311\Lib\site-packages\discum-1.4.1-py3.11.egg\discum\gateway\session.py", line 233, in hasMembers
if self.guildID not in Session.settings_ready['guilds']:
~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
KeyError: 'guilds'
Can you please take a look into this?