Merubokkusu/Discord-S.C.U.M

KeyError: 'username'

Romhast opened this issue · 1 comments

i want to know the username of the users but i am getting an error how can i do

import discum

with open("token.txt",'r') as f:
    bot = discum.Client(token=''.join(f.readlines()), log=False)

def close_after_fetching(resp, guild_id):
    if bot.gateway.finishedMemberFetching(guild_id):
        lenmembersfetched = len(bot.gateway.session.guild(guild_id).members)
        print(str(lenmembersfetched) + ' members fetched')
        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=['username', 'discriminator', 'avatar', 'premium_since', 'roles'])
    bot.gateway.command({'function': close_after_fetching, 'params': {'guild_id': guild_id}})
    bot.gateway.run()

    return bot.gateway.session.guild(guild_id).members


members = get_members('951783170775318548', '1030168144662245457')
print(members['username'])

i want to know the username of the users but i am getting an error how can i do

import discum

with open("token.txt",'r') as f:
    bot = discum.Client(token=''.join(f.readlines()), log=False)

def close_after_fetching(resp, guild_id):
    if bot.gateway.finishedMemberFetching(guild_id):
        lenmembersfetched = len(bot.gateway.session.guild(guild_id).members)
        print(str(lenmembersfetched) + ' members fetched')
        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=['username', 'discriminator', 'avatar', 'premium_since', 'roles'])
    bot.gateway.command({'function': close_after_fetching, 'params': {'guild_id': guild_id}})
    bot.gateway.run()

    return bot.gateway.session.guild(guild_id).members


members = get_members('951783170775318548', '1030168144662245457')
print(members['username'])

you should learn some basic python, you're using get_members which returns a dict which you can go through with for