'discord.py auto delete link has no response

So I am making a bot where if you send anything that has .com in it, it will delete that message and send a message saying "your message contained a link", but the bot is not working. I have tried a lot of different ways but still cannot get it to work!

#--- blacklisted words --- 
@bot.event
async def on_message(message):
  links = [
    ".com"
  ]
  if any(word in message.content.lower() for word in links):
    await message.delete()
    await message.channel.send("Your message contained a blacklisted word!")

I've made sure the bot had perms, checked spellings and everything else I could think of.



Solution 1:[1]

add

intents = discord.Intents(message_content=True)

kwarg to your bot.

for example

bot = discord.Client(intents=intents)

make sure you have enabled the message intent on developer panel

Try testing your command by adding print

@bot.event
async def on_message(message):
  links = [
    ".com"
  ]
  if any(word in message.content.lower() for word in links):
    print('filter matched for message')
    await message.delete()
    print('deleted message')
    await message.channel.send("your emssage contained a blacklisted word!")
    print('sent response')

check what went wrong

This is the solution if you are using discord.py V2. The code you have provided is very less for reproducing the issue

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sashank