【问题标题】:How to get username of user not in Discord guild?如何获取不在 Discord 公会中的用户的用户名?
【发布时间】:2019-12-25 12:44:15
【问题描述】:

我正在使用 discord.py,并且 例如这段代码:

m = ctx.guild.get_member(user_id) 
m.name

返回用户名,但这仅适用于使用具有给定代码的命令的行会中的成员。 如果用户不在公会中,但我们有user_id,如何获取用户的姓名?

【问题讨论】:

标签: python discord discord.py


【解决方案1】:

您可以使用Client.get_user 从用户缓存中检索用户。否则,如果您的机器人不与用户共享任何公会,您可以使用Client.fetch_user,这是一个 API 调用和协程。然后您可以像以前一样使用User.name 属性。

【讨论】:

    猜你喜欢
    • 2021-06-23
    • 2019-05-03
    • 2023-04-11
    • 2021-11-29
    • 2019-12-30
    • 2021-10-16
    • 1970-01-01
    • 1970-01-01
    • 2020-07-05
    相关资源
    最近更新 更多