1

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}")

Edit: For anyone that had a similar problem, while not mentioned in the docs, discord.Member can take user ids aside from @username so there isn't any need for a complicated way.

jitter
  • 29
  • 1
  • 1
  • 8

3 Answers3

4

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()
async def avatar(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()
async def avatar(ctx, *,  avamember : discord.Member=None):
    userAvatarUrl = avamember.avatar_url
    await ctx.send(userAvatarUrl)
Kelo
  • 1,464
  • 2
  • 6
  • 17
  • Nope. I wasn't tagging them, just inputting their id. But yeah, your solution worked. Thanks. – jitter Jan 18 '20 at 12:16
0
if message.content == '!avatar':
    clientProfilePicture = message.author.avatar_url
    await message.channel.send(clientProfilePicture)
-4

A more optimized version of the code:

@bot.command()
async def get_user_icon(ctx, member:discord.Member):
    await ctx.send(member.avatar_url)
Community
  • 1
  • 1