问题
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