Discord.py get user object from id/tag

吃可爱长大的小学妹 提交于 2020-04-11 17:37:24

问题


So i'm trying to get a user object from an id or tag, however i am using a user account not a bot account so i cant use get_user_info() Is there any way to do this on an user account?


回答1:


I you know the user id, I suggest using

user = bot.get_user(user_id)

instead (documentation here).




回答2:


If you're using commands, you can use a converter

@bot.command(pass_sontext=True)
async def mycommand(ctx, user: discord.User):
    # user is a User object

Other wise, you can use Client.get_all_members to get all Member objects you can see.

from discord.utils import get

user = get(bot.get_all_members(), id="1234")
if user:
    # found
else:
    # Not found



回答3:


You can use:

ctx.message.server.get_member("id") or message.server.get_member("id")

This will return you a discord.Member object.



来源:https://stackoverflow.com/questions/54499864/discord-py-get-user-object-from-id-tag

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