Discord.py: User.roles is undocumented

Created on 1 Aug 2018  路  7Comments  路  Source: Rapptz/discord.py

http://discordpy.readthedocs.io/en/latest/api.html#user should contain a variable entry for User.roles

image

invalid

Most helpful comment

I created this library so I feel like I would know what's a thing and what isn't. In your case, user parameter is a Member -- not a User.

All 7 comments

User doesn't have a roles attribute.

I definitely just used it. Here is a quick repro script:

import discord
import asyncio

client = discord.Client()

@client.event
async def on_ready():
    print('Logged in as')
    print(client.user.name)
    print(client.user.id)
    print('------')

@client.event
async def on_reaction_add(reaction, user):
    for role in user.roles:
        print(str(role) + ": " + str(role.id))


client.run('token')

output after I add a reaction to a msg in discord

$ python UserRolesRepro.py
Logged in as
ZeroObserver
473933308015673365
------
@everyone: 421033509654626315
Admin: 421036180231159838
Zero Engine Writer: 422866783704186881
Zero Engine Developer: 421370400501661696

If you want me to take a gif or something I can, but this is definitely a thing.

Just because you call a Member instance "user" it doesn't make it a User class.

I created this library so I feel like I would know what's a thing and what isn't. In your case, user parameter is a Member -- not a User.

I feel like this wasn't very well explained so, a member is a user with guild specific attributes such as roles. a user is not guild specific and so doesn't have guild specific attributes

Library Docs for Member

Represents a Discord member to a Server.

This is a subclass of User that extends more functionality that server members have such as roles and permissions.

Always check the docs first, then when in doubt, ask in the official discord.py Discord server. Github issues should be honestly the last resort.

Ahhh, this makes sense now. When I was looking at the docs for on_reaction_add it uses the name user for the 2nd parameter and lists User before Member in the possible types user could be. I don't think I ever looked back after I original read the entry and just assumed the type was User.

image
I should have done the further type checking to confirm my assumptions, and that is my bad.

Sorry if my 2nd response came across wrong, I was just trying to provide a repro for something I thought was a simple documentation issue, that I thought I had proof of. I definitely should have included why I thought there was a roles attribute in the original issue text, I probably would have gotten a more informative response.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

PicklesJars picture PicklesJars  路  3Comments

danshat picture danshat  路  3Comments

j0hnmeow picture j0hnmeow  路  3Comments

synbitz picture synbitz  路  3Comments

JackL0 picture JackL0  路  3Comments