dolfies / discord.py-self

A fork of the popular discord.py for user accounts.
https://discordpy-self.rtfd.io/en/latest/
MIT License
717 stars 163 forks source link

NoneType user has no attribute 'name' #78

Closed ItsRohan0165 closed 3 years ago

ItsRohan0165 commented 3 years ago

I've updated my discord.self-py to 1.9.1 with a hope that It'll fix the NoneType user thingy but it doesn't resolve it at all. The bot doesn't fetch the user data with bot.get_user(userid). Please Fix it.

dolfies commented 3 years ago

get_user() is returning None because you don't have that user cached.

If you need to get users frequently, try messing with the guild subscription settings.
Else, use something like this:

async def retrieve_user(user_id):
    user = bot.get_user(user_id)
    if user is None:
        user = await bot.fetch_user(user_id)

    return user