获取某人的头像并将其用于我的个人资料discord.py

2024-05-14 00:11:22 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我试着做一个自我机器人,当我提到某人时,机器人会用提到的人的化身来改变我的化身。可能吗

我使用的代码是:

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

但idk如何获得提及者的化身


Tags: 代码asyncdefbot机器人awaiteditcommand
1条回答
网友
1楼 · 发布于 2024-05-14 00:11:22

如果您只想获得用户的化身,可以使用以下方法:

@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

相关问题 更多 >