ShadowNotFake
ShadowNotFake

Reputation: 114

Bot doesn't want to add role

I want bot to add a role to message author.

@client.command(pass_context=True)
@commands.has_role("🍿║Участники")
async def поздравить(ctx, *, text=None):
    role = discord.utils.find(lambda r: r.id == 774543492806475816, ctx.message.guild.roles)
    if role in ctx.author.roles:
        already=discord.Embed(title=':clipboard:!поздравить:clipboard:', colour = discord.Colour.orange(), description=f'**:x:{ctx.author.mention}, вы уже поздравляли Shadow:3**')
        await ctx.send(embed=already)
        await ctx.message.delete()
        return
    else:
        success1=discord.Embed(title=':green_book:Спасибо за поздравление!:green_book:', description=f':white_check_mark:**{ctx.author.mention}, спасибо за поздравление! Оно отправлено Shadow и вы получаете {role.mention}!**\n\n***:milky_way:Текст поздравления:*** {text}', colour=discord.Colour.green())
        await ctx.send(embed=success1)
        user=ctx.message.author
        await client.add_roles(user, role)
        await ctx.message.delete()

When I am executing this command, I get this:

discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'Bot' object has no attribute 'add_roles'

Upvotes: 0

Views: 61

Answers (1)

Just for fun
Just for fun

Reputation: 4225

Its Member.add_roles() not Bot.add_roles()

Below is the revised code:

@client.command(pass_context=True)
@commands.has_role("🍿║Участники")
async def поздравить(ctx, *, text=None):
    role = discord.utils.find(lambda r: r.id == 774543492806475816, ctx.message.guild.roles)
    if role in ctx.author.roles:
        already=discord.Embed(title=':clipboard:!поздравить:clipboard:', colour = discord.Colour.orange(), description=f'**:x:{ctx.author.mention}, вы уже поздравляли Shadow:3**')
        await ctx.send(embed=already)
        await ctx.message.delete()
        return
    else:
        success1=discord.Embed(title=':green_book:Спасибо за поздравление!:green_book:', description=f':white_check_mark:**{ctx.author.mention}, спасибо за поздравление! Оно отправлено Shadow и вы получаете {role.mention}!**\n\n***:milky_way:Текст поздравления:*** {text}', colour=discord.Colour.green())
        await ctx.send(embed=success1)
        user=ctx.message.author
        await user.add_roles(role)
        await ctx.message.delete()

Upvotes: 1

Related Questions