从设置的用户获取个人资料图片

Ted*_*ddy 4 python discord discord.py

我希望让我的机器人使用硬编码的用户个人资料图片回复我的命令。

这是我现在拥有的代码,因为它回复 message.author 的 pfp,我想知道是否以及如何替换user = message.author 它以针对硬编码用户。

if message.content.upper().startswith('TEST'):
userID = message.author.id
user = message.author
pfp = user.avatar_url
embed = discord.Embed(
  title="test",
  description='<@%s>, test' % (userID),
  color=0xecce8b
)
embed.set_image(url=pfp)

await client.send_message(message.channel, embed=embed) `
Run Code Online (Sandbox Code Playgroud)

我也知道,如果我切换到“for user in message.mentions”,我可以让它弹出提到的用户的 pfp,但同样,我希望能够在不提及任何人的情况下做到这一点。

感谢您的时间和提出的任何答案!

Pat*_*ugh 6

您可以使用Server.get_member来解析Member您拥有 id 的对象。

if message.content.upper().startswith('TEST'):
    user = message.server.get_member("116273596605049942") # Fake snowflake, will not work
    if not user:
        return # Can't find the user, then quit
    pfp = user.avatar_url
    embed=discord.Embed(title="test", description='{}, test'.format(user.mention) , color=0xecce8b)
    embed.set_image(url=(pfp))
    await client.send_message(message.channel, embed=embed)
Run Code Online (Sandbox Code Playgroud)