Search code examples
python-3.xdiscordbotsdiscord.py

client.get_user() isn't working in discord.py


I've been trying to get a user object from an ID, but it returns "NoneType". Here is my code:

user = client.get_user(INT)

Client is defined in my code as:

client = discord.Client()

EDIT: INT would be replaced with a valid ID, which I have done in my actual code


Solution

  • To get a member object, your bot need members intent, which is disabled by default. To get it you have to do two things:

    1. Go to the developer portal and under 'bot' ==> 'Privileged Gateway Intents' toggle 'SERVER MEMBERS INTENT' to be on.
    2. Enable it in your client, like:
    intents = discord.Intents.default()
    intents.members = True
    
    client = discord.Client(intents=intents)