So I was programming a discord bot in python. But there is a problem. I know how to mention the user who sent the message. But how do I get the ID of a user that is mentioned by the author in the message? I couldn't get the answer.
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
You can get the user(s) that were mentioned in a message using
message.mentions
(async rewrite)From there, you can either get the ID from the Member object, or get a formatted mention from those objects
discord.Message
objects have an attribute ofmentions
that returns a list ofdiscord.Member
objects of all users mentioned in the message content,discord.Member
objects havediscord.User
objects as parents so you can accessdiscord.User
attributes likeauthor.id
andauthor.name
etc. simply iterate over the mentions withYou should really be using
discord.ext.commands
(async rewrite) because making a command parser that purely works inon_message
event method is a bad non pythonic idea.What you probably want
seems like all you just want is to be able to access the author object of the message and the users mentioned in the message as parameters, for that please consult my answer here. To access the author you can simply do it through the
discord.Message
object withmessage.author