Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Add role Python Discord Bot

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

@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

>Solution :

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}')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading