-1

There is a problem with my code. it does not run any commands :( I know for a fact that the problem is from the on_message part but i dont know how to fix it sadly.

import discord
from discord.ext import commands

bot = commands.Bot(command_prefix='//')
bdl = open('*Filelocation*', 'r')
badwordslist = bdl.read().split()
bdl.close()
   
@bot.command()
async def hello(context):
    print('it works')
    context.send('Hello!')

@bot.event
async def on_connect():
    print('Connected.')
    
@bot.event
async def on_ready():
    print('READY.')
    
@bot.event
async def on_message(message):
    for badword in message.content.lower().split():
        if badword in badwordslist:
            await message.channel.send(f'Hey! {message.author.mention} ! Don\'t be rude!')
            print(f'{message.author} Said A Bad Word.')
            break
        else:
            return
    
bot.run("*Token*")
Timus
  • 10,974
  • 5
  • 14
  • 28
  • 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 25 '22 at 14:09

1 Answers1

3

on_message event blocks other commands. If you want to prevent this, you should process commands with await bot.process_commands(message)

@bot.event
async def on_message(message):
    for badword in message.content.lower().split():
        if badword in badwordslist:
            await message.channel.send(f'Hey! {message.author.mention} ! Don\'t be rude!')
            print(f'{message.author} Said A Bad Word.')
            break
    await bot.process_commands(message)
Nurqm
  • 4,715
  • 2
  • 11
  • 35