[英]Discord.py: How do I get the user name from the user ID
Yeah, so I got the user ID of the Users, but I'm unable to find code to get the user name, like I tried everything like client.fetch_user(payload.user_id)
and client.get_user(user_id)
but it won't work.是的,所以我得到了用户的用户 ID,但是我无法找到获取用户名的代码,就像我尝试
client.fetch_user(payload.user_id)
和client.get_user(user_id)
之类的所有方法但它不会不工作。
Here is the code:这是代码:
@client.command(pass_context = True)
async def test(ctx,id):
print(getname(id))
def getname(a):
return client.get_user(a).name
thanks.谢谢。
If you're trying to have have it in a different function then you can do:如果您想将它放在不同的 function 中,那么您可以这样做:
async def getname(ctx):
user = await ctx.author.guild.fetch_member(id)
return user
If you're trying to get the name specifically try adding .name
behind ctx.author.guild.fetch_member(id)
如果您想专门获取名称,请尝试在
ctx.author.guild.fetch_member(id)
后面添加.name
Maybe this is the answer you're looking for?也许这就是您正在寻找的答案?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.