简体   繁体   中英

discord.py how do I get a bot to send a message when a specific user types?

I'm trying to get my bot to type when a specific member types. How would I be able to use their ID, or get their discord ID and allow the bot to use it to detect that they are the author of the message

The simplest way to do so is to use the ID of that user as reference

If you have developer mode activated on your personal discord client, right click on a user and click "copy the ID" (or something like that)

Now, on the discord.py API , you can find everything you need about objets and their attributes.

the Message class has a author attribute which is of class Member . And the Member class has a id attribute, which is an integer. You should write inside the on_message method:

async def on_message(self, message):
    if message.author.id == id_of_the_user_as_integer:
        # Do what you want

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM