【问题标题】:Get profile picture from set user从设置的用户获取个人资料图片
【发布时间】:2018-12-27 15:54:49
【问题描述】:

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

这是我现在拥有的代码,因为它回复了 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) `

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

感谢您抽出宝贵时间和任何答案!

【问题讨论】:

  • pfp 是什么意思?我不熟悉这个词。
  • 我的错,它代表“头像”又名:“头像”
  • 出于好奇,你为什么要这样做?
  • 出于俗气的原因 x:

标签: python discord discord.py


【解决方案1】:

您可以使用Server.get_member 来解析您拥有ID 的Member

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)

【讨论】:

    【解决方案2】:

    答案是从 1.5.1

    开始的不和谐重写工作
    author = ctx.message.author
    pfp = author.avatar_url
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-20
      • 1970-01-01
      • 2018-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-15
      • 1970-01-01
      相关资源
      最近更新 更多