thisbejim / Pyrebase

A simple python wrapper for the Firebase API.
2.07k stars 529 forks source link

TypeError: 'NoneType' object is not iterable #334

Open Creveoolus opened 4 years ago

Creveoolus commented 4 years ago

I want t omake an Discord bot with pyrebase, i created all what it needs. But when it stores all users i got this error:

File "bot.py", line 43, in on_member_join for user in all_users.each(): TypeError: 'NoneType' object is not iterable

It's on the "for user in all_users.each()" How can i solve it? Code: `@client.event async def on_member_join(member): guild = discord.utils.find(lambda g: g.id == 691365905577410630, client.guilds) channel = discord.utils.find(lambda c: c.id == 691366354430853123, guild.text_channels)

e = discord.Embed(color=discord.Color.from_rgb(53, 188, 217), title='Neuer Mitschüler!', description=f'some text here')
await channel.send(embed=e)

folder = os.listdir('./cogs')

firebase = pyrebase.initialize_app(config)
db = firebase.database()

memberid = member.id

issue = False

all_users = db.child("users").get()
print(type(all_users))
for user in all_users.each():
    if user.key() == memberid:
        issue = True
    else:
        pass
if issue == True:
    pass

else:
    puchData = {
        "id": memberid,
        "warns": 0
    }
    db.child('users').child('{}'.format(memberid)).push(pushData)
    print('New user created')
print('Data base; new: {}'.format(memberid))`
itsonegeneral commented 4 years ago

You might be getting the error because you are trying to get a non-existing child in db, I also face the problem, I solved it by putting the for-in loop inside the try-except block. I'm also still unaware of officially checking the child's existence