'AutoMod causing issues in Discord.py

I am currently trying to program a Discord Bot using discord.py. If I comment out the "Auto Moderation" section of my program, the Bot will work. However, when I use the "Auto Moderation" in my program, the bot only runs Auto Moderation and not anything else. Can anybody help me find a way to make sure that everything in the program works?

Here is my code:

#-----------------------------------Setup----------------------------------
import os
import keep_alive
import discord
from discord.ext import commands, tasks
import random
import asyncio
import time
from itertools import cycle
import aiofiles

bot = commands.Bot(command_prefix='?')
bot.remove_command("help")
bot.warnings = {} 

@bot.event
async def on_ready():
    print('Logged in as')
    print(bot.user.name)
    print(bot.user.id)
    print('------')
    await bot.change_presence(status = discord.Status.online, activity=discord.Game("Some Trashy Games! "))
  
#slowmode command
@bot.command()
@commands.has_permissions(manage_messages=True)
async def slowmode(ctx, seconds: int):
    await ctx.channel.edit(slowmode_delay=seconds)
    slowmode_embed = discord.Embed(title="Slowmode", description="A slowmode was set for this channel", colour=discord.Colour.green())
    await ctx.send(embed=slowmode_embed, delete_after=5.0)

#----------------------------------Auto Moderation-------------------------------------

#bad words
bad_words = ["a", "b", "c", "d", "e"]

@bot.event
async def on_message(msg):
  for bad_word in bad_words:
    if bad_word in msg.content.lower().split(" "):
      await msg.delete()
      bad_word_embed = discord.Embed(title = "Bad Word", description=f"{msg.author.mention}, please do not say any bad words", color = discord.Color.green())
      await msg.channel.send(embed=bad_word_embed, delete_after=5.0)

#--------------------------Errors----------------------------------------
@bot.event
async def on_command_error(ctx, error):
  if isinstance(error, commands.CommandNotFound):
    embed1 = discord.Embed(title = "Error", description = "Not a valid command", color = discord.Color.green())
    await ctx.send(embed = embed1)

#------------------------Keeps Bot Alive---------------------------------
bot.run(token)



Sources

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

Source: Stack Overflow

Solution Source