1
votes

I'm trying to get a user object from a message (specifically a command) - example:

$info Account#0001

Sometimes Discord doesn't register the member (probably to save memory in servers with a large amount of members) so you can't @ them and get the user object when they're out of the channel. I'm trying to make the bot search for that one member#tag, get their ID and then it does whatever the command does.

I've tried

message.mentions[0].id

however it only works whenever the user is pinged, any ideas?

1

1 Answers

1
votes

In the command, you can add an argument for the user:

@bot.command()
async def foo(ctx, user: discord.User):
    print(user.id)

This will allow either the mention or username#tag to be used.