1

Commands not working but events are tried overriding my on_message but that didn't work. When I comment out the second client.event and down client.command works. Any idea of what I could be doing wrong? am I missing something?

import discord
from discord.ext import commands
import random
import time 
from datetime import date

client = commands.Bot(command_prefix = '.')

#client = discord.Client()



@client.event
async def on_ready():
print('we have logged in as {0.user}'.format(client))


@client.command()
async def clr(ctx, amount=5):
   await ctx.channel.purge(limit=amount)



@client.command(aliases =['should', 'will'])
async def _8ball(ctx):
    responses =['As i see it, yes.',
                'Ask again later.',
                'Better not tell you now.',
                "Don't count on it",
                'Yes!']
    await ctx.send(random.choice(responses))


 @client.event()
async def on_message(message):
  if message.author == client.user:
     return
    
    

  if message.content.startswith('hello'):
     await message.channel.send('Hello how are you?')
    
Maicon Mauricio
  • 2,052
  • 1
  • 13
  • 29
  • https://discordpy.readthedocs.io/en/latest/faq.html#why-does-on-message-make-my-commands-stop-working – moinierer3000 Jul 15 '21 at 00:38
  • Does this answer your question? [discord.py @bot.command() not running](https://stackoverflow.com/questions/65207823/discord-py-bot-command-not-running) – TheFungusAmongUs Mar 15 '22 at 15:33

1 Answers1

2

Based on the docs (the ones mentioned by moinierer3000 in the comments) as well as other questions on stack (listed below), on_message will stop your commands from working if you do not process the commands.

@client.event()
async def on_message(message):
  if message.author == client.user:
     return
  if message.content.startswith('hello'):
     await message.channel.send('Hello how are you?')
  await client.process_commands(message)

Other questions like this:

Bagle
  • 2,326
  • 3
  • 12
  • 36