Add role Python Discord Bot

Question:

Some help if possible please. I am using the below code to achieve adding a role to a member by using the command : @addRole @user knight . But the role isnt being added. Can anyone spot my error ?

@ is my prefix and
knight is the name of the role

Here is the code im using :

@client.command(pass_context = True)
@commands.has_permissions(manage_roles = True)
async def addRole(ctx, user : discord.member, *, role : discord.role):

    if role in user.roles:
        await ctx.send(f'{user, mention} already has the {role} role')
    else:
        await user.add_roles(role)
        await ctx.send(f'Added role to {user.mention}')

Many thanks in advance

Asked By: Stephen Probert

||

Answers:

You need to capitalize member and role: discord.Member discord.Role

@client.command(pass_context = True)
@commands.has_permissions(manage_roles = True)
async def addRole(ctx, user : discord.Member, *, role : discord.Role):

    if role in user.roles:
        await ctx.send(f'{user, mention} already has the {role} role')
    else:
        await user.add_roles(role)
        await ctx.send(f'Added role to {user.mention}')
Answered By: Vlone