I have a automod setup but when i try to mention the user when they have triggered the event, i get a ctx error and it says that author is not defined

Viewed 237

This is the code below. How do i define ctx here? This is the error that i get, NameError: name 'ctx' is not defined

async def on_message(message):
    if message.author.id == bot.user.id:
        return
    msg_content = message.content.lower()

    curseWord = [insert bad words here]
    author = message.author.id

    if any(word in msg_content for word in curseWord):
      await message.delete()
      embed=discord.Embed(title="No No Word", description=f"Hey {ctx.author.name} Those words arent allowed here!", color=0x00FFFF)
      await ctx.send(embed=embed)
    else:
      await bot.process_commands(message)
1 Answers

you can use it

async def on_message(ctx: discord.ext.commands.Context, message):
    if message.author.id == bot.user.id:
        return
    msg_content = message.content.lower()

    curseWord = [insert bad words here]
    author = message.author.id

    if any(word in msg_content for word in curseWord):
      await message.delete()
      embed=discord.Embed(title="No No Word", description=f"Hey {ctx.author.name} Those words arent allowed here!", color=0x00FFFF)
      await ctx.send(embed=embed)
    else:
      await bot.process_commands(message)
Related