R
R
Renat Ataev2020-08-21 13:26:56
Python
Renat Ataev, 2020-08-21 13:26:56

Discord.py command ignoring?

Good afternoon. I made myself a bot and wanted to check for user and guild registration in the database. For this I used on_message to get all the messages from the guilds. But here is the problem. The bot now ignores basic commands. It seems to be googled correctly, but there is no answer. Help

The code itself

client = commands.Bot(command_prefix=config.PREFIX)
client.remove_command('help')

@client.event
async def on_message(ctx):
  try:
    print(ctx)

  except AttributeError:
    pass

#Test command
@client.command(pass_context=True)
async def test(ctx):
  await ctx.send('`Привет`')

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Nevzorov, 2020-08-21
@fanepka

FAQ/Why does on_message make my commands stop w... :

Replacing the default `on_message` prevents any additional commands from being executed. To fix this, add the line `bot.process_commands(message)` at the end of your `on_message`, like so:

@bot.event
async def on_message(message):
    # делаем что-нибудь тут

    await bot.process_commands(message)

R
ratratrat, 2020-08-21
@rattratrat

in addition: the indents are incorrectly placed, you have 2 of them, but there should be 4 (!)

client = commands.Bot(command_prefix=config.PREFIX)
client.remove_command('help')

@client.event
async def on_message(ctx):
    try:
        print(ctx)

    except AttributeError:
        pass

#Test command
@client.command()
async def test(ctx):
    await ctx.send('`Привет`')

also in the new version you can drive client.commandin without pass_context
also I advise you to use Tab for quick indentation

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question