I'm making a discord bot with discord.py. How do I get the ID of a user mentioned in a message?
For example, if someone types Hello @user
The bot would detect the @user and find the id of that user.
I'm making a discord bot with discord.py. How do I get the ID of a user mentioned in a message?
For example, if someone types Hello @user
The bot would detect the @user and find the id of that user.
The message object has a message.mentions field that is an array of type Member. Members have an id field which is equivalent to User.id. To get the id of a mentioned member:
message.mentions[0].id
If no one's been mentioned, the array will be empty. It's also worth noting that it's not in any particular order, so if multiple users have been mentioned the first index won't necessarily correspond to the first mention.