Why does on_message stop commands from working?

Multi tool use
Multi tool use


Why does on_message stop commands from working?



Basically, everything appears to work fine and start up, but for some reason I can't call any of the commands. I've been looking around for easily an hour now and looking at examples/watching videos and I can't for the life of me figure out what is wrong. Code below:


import discord
import asyncio
from discord.ext import commands

bot = commands.Bot(command_prefix = '-')
@bot.event
async def on_ready():
print('Logged in as')
print(bot.user.name)
print(bot.user.id)
print('------')

@bot.event
async def on_message(message):
if message.content.startswith('-debug'):
await message.channel.send('d')

@bot.command(pass_context=True)
async def ping(ctx):
await ctx.channel.send('Pong!')

@bot.command(pass_context=True)
async def add(ctx, *, arg):
await ctx.send(arg)



The debug output I have in on_message actually does work and responds, and the whole bot runs wihout any exceptions, but it just won't call the commands.




1 Answer
1



From the rewrite 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:


on_message


bot.process_commands(message)


on_message


@bot.event
async def on_message(message):
# do some extra stuff here

await bot.process_commands(message)



If you have questions about the discord.ext.commands extension, the rewrite documentation is the place to check. Unfortunately there doesn't seem to be any effort to write equivalent documentation for the async branch.


discord.ext.commands





Just tried it out and I made sure it works. Thank you very much!
– Acemcbean
Mar 17 at 0:59






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Z,j k0ve84R0sO8S9F8Pu,mvU0r8OVuSMODRUSDZwxFGvsb 1Thi306c V3lqqRKkGvUF1cI dQyAf,D uv wqm
TihBKC

Popular posts from this blog

PySpark - SparkContext: Error initializing SparkContext File does not exist

django NoReverseMatch Exception

Audio Livestreaming with Python & Flask