Rapptz / discord.py

An API wrapper for Discord written in Python.
http://discordpy.rtfd.org/en/latest
MIT License
14.74k stars 3.75k forks source link

'User' object has no attribute 'roles'? #1024

Closed IanGolsby closed 6 years ago

IanGolsby commented 6 years ago

A few days ago my code worked just fine with checking permissions before doing things (so as not to have to handle 403 Forbidden errors), but today it crashes every time it tries to check permissions. Here's the whole error: Ignoring exception in on_message Traceback (most recent call last): File "C:\Users\Ian Golsby\AppData\Local\Programs\Python\Python35-32\lib\site-packages\discord\client.py", line 307, in _run_event yield from getattr(self, event)(*args, **kwargs) File "C:\Users\Ian Golsby\AppData\Local\Programs\Python\Python35-32\.selfbot.py", line 25, in on_message if client.user.permissions_in(message.channel).manage_messages and client.user.permissions_in(message.channel).read_message_history: File "C:\Users\Ian Golsby\AppData\Local\Programs\Python\Python35-32\lib\site-packages\discord\user.py", line 124, in permissions_in return channel.permissions_for(self) File "C:\Users\Ian Golsby\AppData\Local\Programs\Python\Python35-32\lib\site-packages\discord\channel.py", line 267, in permissions_for for role in member.roles: AttributeError: 'User' object has no attribute 'roles To reiterate, my code was not changed between the last time it worked and the first time I got this error.

Vexs commented 6 years ago

Most likely someone is DMing your bot. DMs have users for authors, not members, because they're not in a server, thus not having roles. You can check for this by checking if message.server is None

IanGolsby commented 6 years ago

Vexs, it's a selfbot and it's getting this error responding to me. The user object it's checking roles for is client.user

Vexs commented 6 years ago

Ah, I should have seen that. User.permissions_in(channel) just calls channel.permissions_for(user), which iterates through the roles the object has. Since a user doesnt have roles, this errors.

Server.me is the member corresponding to you, and shouldn't error (excepting dm's)

I don't know why this code would have worked earlier.

I'd feel amiss if I didn't mention selfbots were banned by discord, and a number of people, including myself, have found their accounts terminated due to using them.

IanGolsby commented 6 years ago

Thanks for your help. And yes, I'm well aware of the potential consequences of selfbots.