如何在不和谐的嵌入消息中获取用户信息
How to get user info in a discord embed message
当我想获取发送命令激活代码的用户的用户信息时 returns 这个字符串:<member 'id' of 'User' objects>
但我希望它显示用户的不和谐 ID . http://prntscr.com/ppf34x
我试图通过添加打印行来调试它,这表明 discord.User.id returns 那段奇怪的文本。我还尝试了文档中描述的不同方法。 (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)
您需要查看特定 User
实例的 id
属性,而不是 User
class 本身。
@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)
当我想获取发送命令激活代码的用户的用户信息时 returns 这个字符串:<member 'id' of 'User' objects>
但我希望它显示用户的不和谐 ID . http://prntscr.com/ppf34x
我试图通过添加打印行来调试它,这表明 discord.User.id returns 那段奇怪的文本。我还尝试了文档中描述的不同方法。 (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)
您需要查看特定 User
实例的 id
属性,而不是 User
class 本身。
@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)