Skip to content

Instantly share code, notes, and snippets.

@V4NSH4J
Created November 6, 2021 07:18
Show Gist options
  • Star 33 You must be signed in to star a gist
  • Fork 20 You must be signed in to fork a gist
  • Save V4NSH4J/06c452f32ceb5f6387b66abd8ccedd74 to your computer and use it in GitHub Desktop.
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()
@SunviZaaminn
Copy link

@SunviZaaminn
Copy link

@soufgameyt
Copy link

@FUNNYPINAY dont put it in onedrive move it to downloads

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment