A
A
Anybody2021-06-11 12:00:22
Python
Anybody, 2021-06-11 12:00:22

How to get user's profile picture in discord.py?

I wanted to get the user's avatar, but the following error pops up:

spoiler
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'Member' object has no attribute 'avatar_url'


Here is a piece of command code:
async def warn(ctx, member: discord.Member, time: int, reason = None):
        role = discord.utils.get(ctx.guild.roles, id=warnrole)
        await member.add_roles(role)
        channel = Bot.get_channel(logchannel)
        emb = discord.Embed(title="Предупреждение", color=0x2f3136)
        emb.set_thumbnail(url=member.avatar_url)
        emb.add_field(name='Модератор', value=ctx.message.author.mention, inline=False)
        emb.add_field(name='Нарушитель', value=member.mention, inline=False)
        emb.add_field(name='Причина', value=reason, inline=False)
        emb.add_field(name="Время", value=time, inline=False)
        await channel.send(embed = emb)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anybody, 2021-06-11
@shurup77

And, that's it, the problem is solved, it is necessary to emb.set_thumbnail(url=member.avatar_url)use not 'avatar_url,' but 'avatar'. Might help someone :)

S
shadowzxc, 2021-06-29
@shadowzxc

async def warn(ctx, member: discord.Member, time: int, reason = None, user: discord.User = None):
        if user is None:
            user = ctx.author
        role = discord.utils.get(ctx.guild.roles, id = warnrole)
        await member.add_roles(role)
        channel = Bot.get_channel(logchannel)
        emb = discord.Embed(title = "Предупреждение", color = 0x2f3136)
        emb.set_thumbnail(url = user.avatar_url)
        emb.add_field(name = 'Модератор', value = ctx.message.author.mention, inline = False)
        emb.add_field(name = 'Нарушитель', value = member.mention, inline = False)
        emb.add_field(name = 'Причина', value = reason, inline = False)
        emb.add_field(name = "Время", value = time, inline = False)
        await channel.send(embed = emb)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question