0

i have been fiddiling with this for the last 2 hours and don't understand why it doesnt work, i have message intents enabled, i have establisbed the commands properly, i am using the right prefix and amount. I've looked over my code multiple times but still do not see or understand why nothing happens, literally nothing happens lol.

from dis import dis
from importlib.metadata import requires
from sys import prefix
from unicodedata import name
from click import command, pass_context
import discord
from discord.ext import commands
import json
import requests
import asyncio

with open('badwords.json', 'r') as f:
    data = json.load(f)

intents = discord.Intents.default()


intents.members = True
intents.message_content = True


print(discord.__version__)

bot = commands.Bot(command_prefix='!', intents=intents)

@bot.event
async def on_ready():
    print(f'{bot.user.name} is Online!')

@bot.event
async def on_message(msg):
    if msg.author != bot.user:
        for text in data['words']:
            if text in msg.content or text.upper() in msg.content or text.capitalize() in msg.content:
                await msg.delete()
                return
    
@bot.command()
@commands.has_permissions(manage_messages=True)
async def purge(ctx, limit: int):
    await ctx.message.delete()
    await asyncio.sleep(1)
    await ctx.channel.purge(limit=limit)
  • 1
    Does this answer your question? [Why does on\_message stop commands from working?](https://stackoverflow.com/questions/49331096/why-does-on-message-stop-commands-from-working) – TheFungusAmongUs Apr 05 '22 at 23:41

1 Answers1

0

In general terms, your 'on_message' event is blocking all other commands from running.

From the documentation

Overriding the default provided on_message forbids any extra commands from running. To fix this, add a bot.process_commands(message) line at the end of your on_message. For example:

async def on_message(message):
   # do some extra stuff here

   await bot.process_commands(message)

The default on_message contains a call to this coroutine, but when you override it with your own on_message, you need to call it yourself.

Original answer here

Edit: In regards to your comment, I assume that you added the 'process_commands' in the wrong place. If I'm not mistaken, then your code should look something like this:

@bot.event
async def on_message(msg):
    if msg.author != bot.user:
        for text in data['words']:
            if text in msg.content or text.upper() in msg.content or text.capitalize() in msg.content:
                await msg.delete()
                return
    await bot.process_commands(message)
Pattles
  • 11
  • 4
  • Im getting this error File "/home/exodus/.local/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 1269, in process_commands if message.author.bot: AttributeError: module 'email.message' has no attribute 'author' –  Apr 05 '22 at 14:42
  • The code at the bottom would result in a `NameError` (what is `message`?). Also, please flag as a duplicate instead of posting a duplicate answer. – TheFungusAmongUs Apr 05 '22 at 23:41