Obtaining username from user id | discord.py

和自甴很熟 提交于 2021-02-13 17:05:43

问题


Well I have been working with databases for a while with discord in order to obtain major lists of user id's in a queue, although I am having problem's obtaining the user from user id as it returns none

For Example


members = list(privateduos[matchid])
user = discord.User(id=int(members[0]))
await client.say("Say `test` " + str(user))
await client.wait_for_message(content="test", author=user)

This is the Output

The client.wait_for_message doesnt seem to detect the message author in the code as well, any solutions?


回答1:


The method client.get_user_info is deprecated since the last Migration, you should use Client.fetch_user() instead

See this link for the details : https://discordpy.readthedocs.io/en/latest/migrating.html




回答2:


Use await client.get_user_info(members[0])

From there on, (assuming that you have allocated the returned value to user) you can do user.name to obtain the username.
(Or fetch other information about the user as stated here.)



来源:https://stackoverflow.com/questions/53672754/obtaining-username-from-user-id-discord-py

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!