Skip to content Skip to sidebar Skip to footer

How To Get A User's Avatar With Their Id In Discord.py?

I tried using the following code but it didn't work. @bot.command() async def avatar(ctx,*, avamember): user = bot.get_user(avamember) await ctx.send(f'{user.avatar_url}')

Solution 1:

I'm presuming you're Tagging the user with @UserNameHere in discord. It's much easier to take that input as a member Object :)

You also don't need to wrap the url in quotes.

This code is if it is in a cog:

@commands.command()asyncdefavatar(self, ctx, *,  avamember : discord.Member=None):
    userAvatarUrl = avamember.avatar_url
    await ctx.send(userAvatarUrl)

This code is if it is in the main bot.py file:

@bot.command()asyncdefavatar(ctx, *,  avamember : discord.Member=None):
    userAvatarUrl = avamember.avatar_url
    await ctx.send(userAvatarUrl)

Solution 2:

I tried using your code but it didn't work ; in the main bot.py :

@bot.command()asyncdefavatar(ctx, *,  avamember : discord.Member=None):
    userAvatarUrl = avamember.avatar_url
    await ctx.send(userAvatarUrl)

Solution 3:

if message.content == '!avatar':
    clientProfilePicture = message.author.avatar_url
    await message.channel.send(clientProfilePicture)

Solution 4:

A more optimized version of the code:

@bot.command()asyncdefget_user_icon(ctx, member:discord.Member):
    await ctx.send(member.avatar_url)

Post a Comment for "How To Get A User's Avatar With Their Id In Discord.py?"