Mashhhyyy
Mashhhyyy

Reputation: 101

Adding addroles into an if statement

I am trying to create a bot.add_role() line into an if statement however It doesn't appear to be working correctly.

This is using Discord.py Python version 3.6.6, I have tried to change what I'm using from bot.add_role(discord.Object(id='526141719159373865')) to bot.add_role(maleRole) which didn't help me whatsoever (Here are lines 49-66)

@bot.command(pass_context = True)
async def gender(ctx, *args):
    gender = ' '.join(args) 

#Checks if variable 'gender' == 'Male'

    if gender == 'Male':

#Deletes message and adds role

        await bot.delete_message(ctx.message)
        return await bot.add_roles(maleRole)
    if gender == 'Female':
        await bot.delete_message(ctx.message)
        await bot.add_roles(femaleRole)
    if gender == 'Boy':
        await bot.delete_message(ctx.message)
        await bot.add_roles(maleRole)
    if gender == 'Girl':
        await bot.delete_message(ctx.message)
        await bot.add_roles(femaleRole)

#If 'gender' doesn't have an expected input.

    else:

#Deletes message and says to enter valid gender.

        await bot.delete_message(ctx.message)
        await bot.say('Please select a valid gender! (`Male` or `Female`)')

I expected it to take the input after -gender to be taken and compared to each if statements, and if it's the same. It'll run what's inside. Which it does. It deletes the message. However doesn't add the role and gives me this error message (http://thedudeinthecorner.xyz/files/ZcDuU.png)

Upvotes: 0

Views: 57

Answers (1)

Patrick Haugh
Patrick Haugh

Reputation: 60944

You need to tell your bot who you want to give the role to:

await bot.add_roles(ctx.message.author, maleRole)

See the documentation for Client.add_roles

Upvotes: 1

Related Questions