简体   繁体   中英

Allow only a message in a chat discord.py

I'm trying to make a only allowed message in a chat. The code I tried deletes every message even if is the correct one. What am I doing wrong?

@bot.event
async def on_message(message):
    if message != '!d bump':
         await message.delete()

You're comparing a Message instance to a string, to get the actual content of the message use the content attribute

@bot.event
async def on_message(message):
    if message.content != '!d bump':
         await message.delete()

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