1

So I can check a user's roles in a server with the following code:

        #Check Admin:
        playerRoles = []
        for x in message.author.roles:
            playerRoles.append(str(x))
        if "Admin" in playerRoles:

But I want bot to be able to detect the roles they have in a different server than where the command was issued. I want the command to be able to be issued by DMing it to the bot, so obviously I can't use message.author.roles because the user doesn't have roles in DMs, he has the role in the server.

Here's what I tried:

        #Check Roles:
        playerRoles = []
        #target the user manually to get his roles in the event of a DM
        pepeServer = client.get_guild(guildID)
        targetUser = discord.utils.get(pepeServer.members, id=userID)
        for x in targetUser.roles:
            playerRoles.append(str(x))

This returns an error on the line "for x in targetUser.roles:"

AttributeError: 'NoneType' object has no attribute 'roles'

I guess the "targetUser" it's obtaining isn't the kind with roles. Feelsbadman. How do I get the user's roles in the server from a command issued in DMs?

Thanks for the help

CityFrog
  • 95
  • 7

1 Answers1

1

AttributeError: 'NoneType' object has no attribute 'roles' means that targetUser is None.

So your discord.utils.get(pepeServer.members, id=userID) doesnt return anything.

Check the server and user id.

xSparfuchs
  • 132
  • 7
  • Wow I feel so stupid for not realizing xD userID was a string and not an integer. First time doing this so I had just assumed my method was wrong. Thanks for your help – CityFrog Apr 25 '20 at 22:40