Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 286
Galaxy_Shot Avatar asked Feb 04 '26 11:02

Galaxy_Shot


1 Answers

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

like image 133
Sashank Avatar answered Feb 06 '26 01:02

Sashank



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!