-2

So im trying to make a self bot that when I mention someone the bot changes my avatar with the mentioned person's avatar. Is that possible?

The code im using is this:

@bot.command()
async def avatar(ctx):
    await bot.user.edit(avatar=pfp)

But idk how to get the mention person's avatar.

  • Does this answer your question? [How to get a user's avatar with their id in discord.py?](https://stackoverflow.com/questions/59799987/how-to-get-a-users-avatar-with-their-id-in-discord-py) – Zoe Mar 09 '21 at 16:46
  • I tried it but it isn't working –  Mar 09 '21 at 17:07
  • I'm pretty sure self-bots are against ToS. – goose.mp4 Mar 19 '21 at 02:43

1 Answers1

0

If you only want to get the user's avatar you can use the following method:

@bot.command()
async def avatar(ctx, *, user: discord.Member = None):
    author = ctx.author

    if not user:
        user = author # Get your avatar if you do not mention someone

    if user.is_avatar_animated():
        url = user.avatar_url_as(format="gif") # Check if it is a GIF
    if not user.is_avatar_animated():
        url = user.avatar_url_as(static_format="png") # If it is not a GIF = PNG

    await ctx.send("{}'s avatar: {}".format(user.name, url)) # Output a link + picture
Dominik
  • 3,612
  • 2
  • 11
  • 44