Skip to content

Instantly share code, notes, and snippets.

Created November 6, 2021 07:18
  • Star 31 You must be signed in to star a gist
  • Fork 15 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
# 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.
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}})
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.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:
f = open('users.txt', "a")
for element in memberslist:
f.write(element + '\n')
Copy link

Abdohelm commented Jan 3, 2023

<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\", 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\", 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\", line 233, in hasMembers
if self.guildID not in Session.settings_ready['guilds']:
KeyError: 'guilds'

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