如何在不和谐的嵌入消息中获取用户信息

时间:2019-10-29 01:03:30

标签: python-3.x discord.py-rewrite

当我想获取发送命令以激活代码的用户的用户信息时,它返回以下字符串:<member 'id' of 'User' objects>,但我希望它显示用户的不和谐ID。 http://prntscr.com/ppf34x

我试图通过添加打印行对其进行调试,这表明discord.User.id返回了那段奇怪的文本。我还尝试了文档中描述的其他方法。 (https://discordpy.readthedocs.io/en/latest/api.html#user

@client.event
async def on_message(message):
    if message.content == "profile":
        user = discord.User.id
        print(user)
        embed = discord.Embed(title="Profile", description="Your Profile")
        embed.add_field(name="Username:", value=f"{message.author}", inline=True)
        embed.add_field(name="Id:", value=f"{discord.User.id}", inline=True)
        await message.channel.send(content=None, embed=embed)

1 个答案:

答案 0 :(得分:1)

您需要查看特定id实例的User属性,而不是User类本身。

@client.event
async def on_message(message):
    if message.content == "profile":
        user = message.author.id
        print(user)
        embed = discord.Embed(title="Profile", description="Your Profile")
        embed.add_field(name="Username:", value=f"{message.author}", inline=True)
        embed.add_field(name="Id:", value=f"{message.author.id}", inline=True)
        await message.channel.send(content=None, embed=embed)