'How to get User roles on discord.py rewrite

New discord.py-rewrite user here.

I'm coding a bot that has a discord interface: It is connected to more than one server (guild) and I currently need an auth system to limit its use. I thought I could get all users roles and parse them later when needed. So I did:

    @client.event
    async def on_ready():
        ... 
        for guild in client.guilds:
            for member in guild.members:
                for role in member.roles:
                    if role.name == "Test":
                        print("USER_ID: %d - ROLE: %s" % (member.id, role.name))

but I don't like it. I have to store these and its not efficient. Also I have to refresh with a background co-routine to check if new members join/changed roles. So my question: is there a simply way to check on the fly user roles on mutual guilds when receiving a message? Scrolling the official API the only way to get user's mutual guilds is profile() but as a bot I get a Forbidden Error, like API says.

    @client.event
    async def on_message(message):
        ...
        profile = await message.author.profile()
discord.errors.Forbidden: FORBIDDEN (status code: 403): Bots cannot use this endpoint

(update) ADDENDUM:

I need to check user's roles even in private messages so the need to get mutual_guilds



Solution 1:[1]

I have looked trough the Documentation, and I don't think there is simpler way to do this.

@commands.command(pass_context=True)
async def test(self, ctx):
    for role in ctx.guild.roles:
        if role.name == 'Your role name':
            #Code

Simply when certain command is called, you check for each role on the guild the message was sent in, and if the role name matches the role name you pick, it will execute certain code.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Aeossa