disnake.SelectOption(
label="", value="1", description="", emoji=""
),
disnake.SelectOption(
label="", value="2", description="", emoji=""
),
@bot.command()
async def shop(ctx):
r1=discord.utils.get(ctx.guild.roles, id=966041637618847794)
emb=discord.Embed(title="Магазин ролей", timestamp=ctx.message.created_at, colour=discord.Color.from_rgb(255, 255, 255))
emb.set_footer(text="{}".format(ctx.author.name), icon_url=ctx.author.avatar_url)
role1=discord.utils.get(ctx.guild.roles, id=966041637618847794)
role2=discord.utils.get(ctx.guild.roles, id=966046291740217384)
counter=0
if ctx.channel.id==955186277270048808:
for row in cursor.execute("SELECT role_id, cost FROM shop"):
if ctx.guild.get_role(row[0]) != None:
counter+=1
emb.add_field(
name=f"{counter}. Стоимость - {row[1]} <:servvalute:967795640425930822>",
value=f"Роль {ctx.guild.get_role(row[0]).mention}",
inline=False
)
else:
pass
counter+=1
await ctx.send(embed=emb, components=[
Select(
placeholder="Выберите роль, которую хотите приобрести.",
options=[
SelectOption(label=f"{role1}", value="r1"),
SelectOption(label=f"{role2}", value="r2")
]
)
])
@bot.event
async def on_select_option(ctx, interaction):
if interaction.channel == ctx.channel:
if interaction.values[0]=="r1":
role=discord.utils.get(ctx.guild.roles, id=966041637618847794)
cursor.execute("UPDATE users SET cash = cash - {} WHERE id = {}".format(cursor.execute("SELECT cost FROM shop WHERE role_id = {}".format(role.id)).fetchone()[0], ctx.author.id))
connection.commit()
await ctx.author.add_roles(role)
await ctx.send(f"{role} успешно приборетена!", ephemeral = True)
elif interaction.values[0]=="r2":
role=discord.utils.get(ctx.guild.roles, id=966046291740217384)
cursor.execute("UPDATE users SET cash = cash - {} WHERE id = {}".format(cursor.execute("SELECT cost FROM shop WHERE role_id = {}".format(role.id)).fetchone()[0], ctx.author.id))
connection.commit()
await ctx.author.add_roles(role)
await ctx.send(f"{role} успешно приборетена!", ephemeral = True)
cursor.execute("""CREATE TABLE IF NOT EXISTS users(
name TEXT,
id INT,
cash BIGINT,
rep INT,
lvl INT,
server_id INT
)""")
cursor.execute("""CREATE TABLE IF NOT EXISTS shop(
role_id INT,
id INT,
cost BIGINT
)""")
@bot.command()
async def buy(ctx, role : discord.Role = None):
if ctx.channel.id == 955186277270048808:
rid=cursor.execute("SELECT role_id, rid FROM shop WHERE id = {}".format(ctx.guild.id))
if rid and role is None:
await ctx.reply(embed=discord.Embed(
timestamp=ctx.message.created_at,
colour=discord.Color.dark_red()
).add_field(name=f'<a:noentr:965583104360198205> | Некорректный ввод команды.',
value=f'Укажите роль, которую хотите приобрести.'
).set_footer(text="{}".format(ctx.author.name),
icon_url=ctx.author.avatar_url),
mention_author=False)
else:
role=cursor.execute("SELECT role_id, rid FROM shop WHERE id = {}".format(ctx.guild.id))
if role in ctx.author.roles:
await ctx.reply(embed=discord.Embed(
timestamp=ctx.message.created_at,
colour=discord.Color.dark_red()
).add_field(name=f'<a:noentr:965583104360198205> | У вас уже имеется такая роль.',
value=f'Попробуйте выбрать другую.'
).set_footer(text="{}".format(ctx.author.name),
icon_url=ctx.author.avatar_url),
mention_author=False)
elif cursor.execute("SELECT cost FROM shop WHERE role_id = {}".format(role.id)).fetchone()[0] > cursor.execute("SELECT cash FROM users WHERE id = {}".format(ctx.author.id)).fetchone()[0]:
await ctx.reply(embed=discord.Embed(
timestamp=ctx.message.created_at,
colour=discord.Color.dark_red()
).add_field(name=f'<a:noentr:965583104360198205> | Недостаточно средств.',
value=f'Накопите немного деньжат и возвращайтесь!'
).set_footer(text="{}".format(ctx.author.name),
icon_url=ctx.author.avatar_url),
mention_author=False)
else:
await ctx.author.add_roles(role)
cursor.execute("UPDATE users SET cash = cash - {} WHERE id = {}".format(cursor.execute("SELECT cost FROM shop WHERE rid = {}".format(rid)).fetchone()[0], ctx.author.id))
connection.commit()
await ctx.reply(embed=discord.Embed(
timestamp=ctx.message.created_at,
colour=discord.Color.from_rgb(27, 227, 124)
).add_field(name=f'<a:Yes1:965581422121353216> | Роль успешно приобретена.',
value=f'Она уже находится в вашем профиле.'
).set_footer(text="{}".format(ctx.author.name),
icon_url=ctx.author.avatar_url),
mention_author=False)
await asyncio.sleep(5)
await ctx.message.delete()
лево - лейаут, право - рендер