Задать вопрос
@user1324

Что не так в этом коде?

Помогите пожалуйста
Код:
@client.command(aliases=['leaderboard', 'lb'])
async def __leaderboard(ctx):
    img = Image.new('RGBA', (680, 745), '#FFD700')
    embed = discord.Embed(title='Топ 10 сервера')
    counter = 0
    x = 0
    for row in cursor.execute("SELECT user_id, lvl FROM users WHERE server_id = {} ORDER BY cash DESC LIMIT 10".format(ctx.guild.id)):
        counter += 1
        member = ctx.guild.get_member(row[0])
        url = str(member.avatar_url_as(format='png'))
        response = requests.get(url, stream=True)
        response = Image.open(io.BytesIO(response.content))
        response = response.convert('RGBA')
        response = response.resize((68, 68), Image.ANTIALIAS)

        img.paste(response, (0, x))

        idraw = ImageDraw.Draw(img)
        name = f'# {counter} | {member.display_name}'
        undertext = ImageFont.truetype('arial.ttf', size=20)

        idraw.text((75, x+20), f'{name}', font=undertext)
        x += 68

    img.save("user_card.png")

    await ctx.send(file=discord.File('user_card.png'))

Ошибка:
Traceback (most recent call last):
  File "C:\Users\dubey\PycharmProjects\pythonProject2\venv\lib\site-packages\discord\ext\commands\core.py", line 229, in wrapped
    ret = await coro(*args, **kwargs)
  File "C:\Users\dubey\PycharmProjects\pythonProject2\main.py", line 199, in __leaderboard
    url = str(member.avatar_url_as(format='png'))
AttributeError: 'Member' object has no attribute 'avatar_url_as'

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

Traceback (most recent call last):
  File "C:\Users\dubey\PycharmProjects\pythonProject2\venv\lib\site-packages\discord\ext\commands\bot.py", line 1350, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\dubey\PycharmProjects\pythonProject2\venv\lib\site-packages\discord\ext\commands\core.py", line 1023, in invoke
    await injected(*ctx.args, **ctx.kwargs)  # type: ignore
  File "C:\Users\dubey\PycharmProjects\pythonProject2\venv\lib\site-packages\discord\ext\commands\core.py", line 238, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'Member' object has no attribute 'avatar_url_as'
  • Вопрос задан
  • 183 просмотра
Подписаться 1 Простой 4 комментария
Пригласить эксперта
Ответы на вопрос 1
@Medovochka
Ошибка возникает из-за того, что атрибут avatar_url_as отсутствует у объекта Member.

Попробуй так:

import requests
import io

@client.command(aliases=['leaderboard', 'lb'])
async def __leaderboard(ctx):
    img = Image.new('RGBA', (680, 745), '#FFD700')
    embed = discord.Embed(title='Топ 10 сервера')
    counter = 0
    x = 0
    for row in cursor.execute("SELECT user_id, lvl FROM users WHERE server_id = {} ORDER BY cash DESC LIMIT 10".format(ctx.guild.id)):
        counter += 1
        member = ctx.guild.get_member(row[0])
        url = str(member.avatar_url)
        response = requests.get(url, stream=True)
        response = Image.open(io.BytesIO(response.content))
        response = response.convert('RGBA')
        response = response.resize((68, 68), Image.ANTIALIAS)

        img.paste(response, (0, x))

        idraw = ImageDraw.Draw(img)
        name = f'# {counter} | {member.display_name}'
        undertext = ImageFont.truetype('arial.ttf', size=20)

        idraw.text((75, x+20), f'{name}', font=undertext)
        x += 68

    img.save("user_card.png")

    await ctx.send(file=discord.File('user_card.png'))
Ответ написан
Комментировать
Ваш ответ на вопрос

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

Похожие вопросы