当我想获取发送命令以激活代码的用户的用户信息时,它返回以下字符串:<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)
答案 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)