0
votes

I have a command that when invoked will take a list of user ids from a mongodb collection, a list of role names from a different mongodb collection and then works through these lists to see which roles need to be assigned to which ids.

I can get it to print out the correct ids that need the role but I just cannot get past the last step of actually assigning the role.

    @commands.command(
        name='assignRolesByExp',
        aliases =['arbe'],
        description="Assign all members roles based on their Exp Points",
        #usage='[Role Name]',
    )
    @commands.has_permissions(administrator=True)
    async def assignRolesByExp(self, ctx):
        people = await self.bot.expAcc.get_all()


        roles = await self.bot.stockroles.get_all()
        filtered_roles=[]
        for i in roles:
            if i["expRequired"]>0:
                filtered_roles.append(i)

        for i in filtered_roles:
            roll_to_add = []
            role_name = i["_id"]
            role_exp_required = i["expRequired"]
            #print(role_name)
            for i in people:
                if i["expValue"]>= role_exp_required:
                    roll_to_add.append(i["_id"])
            
            for i in roll_to_add:
                user= ctx.guild.get_member(i)
                await user.add_roles(role_name)

The error I get is: File "D:\WORK\DISCORD BOT\Tranquility\cogs\roles.py", line 339, in assignRolesByExp await user.add_roles(role_name) File "C:\Users\johnj\AppData\Roaming\Python\Python38\site-packages\discord\member.py", line 676, in add_roles await req(guild_id, user_id, role.id, reason=reason) AttributeError: 'str' object has no attribute 'id'

1

1 Answers

0
votes

It seems like you're passing a str rather than a Role to add_roles as defined in the discord.py documentation. Impossible however to say how to go about fixing that without access to the rest of the source code, just make sure that you are retrieving the Roles as actual Role objects rather than just their string names.