@Zw1le

Почему не работает скрипт?

Код:
@bot.slash_command(name = "rank", description = "Показывает рейтинг упомянутого пользователя")
async def rank(ctx, member: discord.Member = None):
    if member == None:
        member = ctx.author
    async with bot.db.cursor() as cursor:
        await cursor.execute("SELECT level FROM levels WHERE user = ? AND guild = ?", (member.id, ctx.guild.id,))
        level = await cursor.fetchone()
        await cursor.execute("SELECT xp FROM levels WHERE user = ? AND guild = ?", (member.id, ctx.guild.id,))
        xp = await cursor.fetchone()

        if not level or not xp:
            await cursor.execute("INSERT INTO levels (level, xp, user, guild) VALUES (?, ?, ?, ?)", (0, 0, member.id, ctx.guild.id,))
        
        try:
            xp = xp[0]
            level = level[0]
        except TypeError:
            xp = 0
            level = 0

    user_data = {
        "name": f"{member.name}#{member.discriminator}",
        "xp": xp,
        "level": level,
        "next_level_xp": 100,
        "percentage": xp,
    }

    background = Editor(Canvas((900,300), color = "#141414"))
    profile_picture = await load_image_async(str(member.avatar))
    profile = Editor(profile_picture).resize((150, 150)).circle_image()

    poppins = Font.poppins(size=40)
    small_poppins = Font.poppins(size=30)

    card_right_shape = [(600,0), (900,300), (900,0)]
    background.polygon(card_right_shape, color = "#FFFFFF")
    background.paste(profile, (30,30))
    background.rectangle((30,220), width=650, height=40, color="#FFFFFF", radius=20)
    background.bar((30,220), max_width=650, height=40, percentage=user_data['percentage'], color="#282828", radius=20,)

    background.text((200,40), user_data['name'], font=poppins, color="#FFFFFF")
    background.rectangle((200,100), width=350, height=2, fill="#FFFFFF")
    background.text(
        (200,130),
        f"Level: {user_data['level']}  |  XP: {user_data['xp']}/{user_data['next_level_xp']}",
        font=small_poppins,
        color = "#FFFFFF",
    )
    file = discord.File(fp = background.image_bytes, filename="rank.png")
    await ctx.respond(file=file)

Ошибка:
spoiler
Ignoring exception in command rank:
Traceback (most recent call last):
File "/home/container/.local/lib/python3.8/site-packages/discord/commands/core.py", line 124, in wrapped
ret = await coro(arg)
File "/home/container/.local/lib/python3.8/site-packages/discord/commands/core.py", line 982, in _invoke
await self.callback(ctx, **kwargs)
File "main.py", line 226, in rank
profile_picture = await load_image_async(str(member.avatar))
RuntimeError: cannot reuse already awaited coroutine

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/home/container/.local/lib/python3.8/site-packages/discord/bot.py", line 1114, in invoke_application_command
await ctx.command.invoke(ctx)
File "/home/container/.local/lib/python3.8/site-packages/discord/commands/core.py", line 375, in invoke
await injected(ctx)
File "/home/container/.local/lib/python3.8/site-packages/discord/commands/core.py", line 132, in wrapped
raise ApplicationCommandInvokeError(exc) from exc
discord.errors.ApplicationCommandInvokeError: Application Command raised an exception: RuntimeError: cannot reuse already awaited coroutine


В чем может быть проблема?
  • Вопрос задан
  • 45 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы