-
-
Save V4NSH4J/06c452f32ceb5f6387b66abd8ccedd74 to your computer and use it in GitHub Desktop.
# 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() |
<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'
same problem
@FUNNYPINAY dont put it in onedrive move it to downloads
i ham having a problem can anyone help me?