itsame
itsame

Reputation: 181

How to get info about the mentioned users (discord.py bot)?

Someone uses the command !getname @testuser, the bot gets the name as a string and could do with it whatever I want. I can't find anything about on the Internet. Maybe the answer is just too obvious.

Also, how could I get the avatar of the mentioned user? And download it or whatever.

Thanks in advance!

Upvotes: 2

Views: 3957

Answers (1)

vgalin
vgalin

Reputation: 526

You can do this by specifying that the type of a parameter is discord.Member :

import requests

@bot.command()
async def getname(ctx, member: discord.Member):

    await ctx.send(f'User name: {member.name}, id: {member.id}')

    with requests.get(member.avatar_url_as(format='png')) as r:
        img_data = r.content
    with open(f'{member.name}.png', 'wb') as f:
        f.write(img_data)

Upvotes: 2

Related Questions