简体   繁体   中英

How do I make my discord bot respond when a specific user sends a message in the channel?

I want to have my discord bot respond every time a specific user sends a message in the chat. The code runs but nothing happens when that user sends a message.

This is what I have tried so far:

@client.event
async def on_message(message):
    if message.author == client.user:
        return
        
    if message.author.id == '546474118711869440':
        await message.channel.send('shhhhh')

It's in a string. You have to put the user id as an int, so no quotes.

if message.author.id == 546474118711869440:
    await message.channel.send('shhhhh')

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