'Discord.py API for discord bot to listen to message, and delete the message in question

I'm looking to make a bot that uses the VirusTotal API to scan URLs sent in discord messages and if any are detected, they will delete the message in question, send a warning, and log the situation in a modlogs channel. This is the code for my on_message so far.

@bot.event
async def on_message(message):
  urls = regex.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*(),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+',message.content.lower())
  flag = False
  for i in urls:
    if (scan_url(i)):
      flag = True
      break
  if flag:
    #delete message, send warning, find the channel named "modlogs" and send the log

scan_url will be used to check each url individually and returns true if the link in question is malicious. I am stuck however on using the bot.event decorator and just a string of the message on how to find the message in question, delete it, send the warning in the same channel, then add to mod logs.



Solution 1:[1]

if flag:
   await message.channel.send(send_warning_message_here)  # Send warning message
   modlogs_channel = discord.utils.get(message.guild.text_channels, name='modlogs')  # Get modlogs channel
   await modlogs_channel.send(send_log_message_here)  # Send log
   await message.delete()  # Delete the message

You could also check if the message content starts with https:// or http://.

if message.content.startswith('https://') or message.content.startswith('http://):
   # Scan URL 

This helps in making API calls only when required.

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 Sandy