Skip to content Skip to sidebar Skip to footer

How Do I Get The Id Of A Mentioned User In A Discord.py Message?

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 t

Solution 1:

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.

Post a Comment for "How Do I Get The Id Of A Mentioned User In A Discord.py Message?"