E
E
Elvinchik2021-12-07 22:01:28
Python
Elvinchik, 2021-12-07 22:01:28

Problem with .add_roles() in discordpy?

@bot.command(pass_context=True)
async def buyrole(ctx, role: discord.Role = None):
with connect.cursor() as cursor:
icon = sql.get_money(ctx.guild.id)
if role is not None :
print(role.id)
cursor.execute(f"SELECT cost FROM roleshop WHERE role_id = {role.id} and server_id = {ctx.guild.id}")
price = cursor.fetchone()[0]
if price:
cursor.execute(
f"SELECT shadow_card FROM users WHERE id = {ctx.author.id} and server_id = {ctx.guild.id}")
balance = cursor.fetchone()[0]
if balance >= price and role not in ctx.author.roles:
cursor.execute(
f"UPDATE users SET shadow_card = shadow_card - {price} WHERE id = {ctx.author.id} and server_id = {ctx.guild.id}")
embed = discord.Embed(
title=" BuyRole",
description=f"You bought role ``{role}`` for ``{price}`` {icon}",
colour=discord.Color.green()
)
await ctx.author.add_roles(role)
else:
embed = discord.Embed(
title=" BuyRole",
description="**You don't have enough funds or you have this role!**",
color=discord.Color.red()
)
else:
embed = discord.Embed(
title=" BuyRole",
description="**This role is not for sale!**",
color=discord.Color.red()
)
else :
embed = discord.Embed(
title=" BuyRole",
description=f"**Enter the role you want to buy**\nExample: ``{p}buyrole @FullStack``",
color=discord.Color.red( )
)
connect.commit()
embed.set_footer(icon_url=ctx.author.avatar_url, text=f"Requested {ctx.author}")
await ctx.send(embed=embed)

The problem is await ctx.author.add_roles(roles) when I I delete the command works stably.

Intents enabled

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question