Discord.py get user object from id/tag
Solution 1:
If you know the user id, I suggest using bot.get_user(user_id)
instead.
Solution 2:
If you're using commands
, you can use a converter:
@bot.command(pass_context=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 the user
else:
# Not found the user
Solution 3:
You can use:
ctx.message.server.get_member(id) or message.server.get_member(id) # id must be of type int
This will return you a discord.Member
object.
Solution 4:
ctx.message.server.get_member(id) or message.server.get_member(id)
I couldn't write a comment to the previous answer (because of reputation) but make sure that id is int type here.