如何获取有关提到的用户(discord.py 机器人)的信息?

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

有人使用命令 !getname @testuser,机器人将名称作为字符串获取,并且可以随心所欲地使用它。我在互联网上找不到任何相关信息。也许答案太明显了。

另外,请问如何获取上述用户的头像?然后下载它或其他任何东西。

提前致谢!

您可以通过指定参数类型为 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)