Why does on_message stop commands from working?
From the documentation:
Overriding the default provided
on_message
forbids any extra commands from running. To fix this, add abot.process_commands(message)
line at the end of youron_message
. For example:@bot.event
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.
i added a log feature for my discord bot and all of the commands don't work
Why does on_message make my commands stop working?
https://discordpy.readthedocs.io/en/latest/faq.html#why-does-on-message-make-my-commands-stop-working
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.
Consider using a listener. In a listener setup you do not need to manually call process_commands()
Listener documentation:
https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.ext.commands.Bot.listen
Examples are provided in both documentation links.
On_message command not letting other commands work
Commands also use some sort of on_message
in the background therefore by adding your own on_message, you're making it take it as you want to use your own on_message thus blocking the default one. To make it use both, add await client.process_commands(message)
to the end of your on_message.
@client.event
async def on_message(message):
if message.content.startswith('!'):
await message.delete()
await client.process_commands(message)
on_message() does not allow @bot.commad() to work
The only time bot.process_commands(message)
is run in your code is if the user types "шутка", which is not what you want. Instead, take the process outside of the if
statement, as seen in the revised code below.
@bot.event
async def on_message(message):
if message.content.lower().startswith('шутка'):
await message.channel.send(random.choice(arr2))
await bot.process_commands(message)
on_message stops all of my bot.commands from working
You need to await
the last line in on_message
as process_commands
is a coroutine.
await client.process_commands(message)
If you send !flip
in discord, you should be able to receive the appropriate response (heads
or tails
).
i added a log feature for my discord bot and all of the commands don't work
Why does on_message make my commands stop working?
https://discordpy.readthedocs.io/en/latest/faq.html#why-does-on-message-make-my-commands-stop-working
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.
Consider using a listener. In a listener setup you do not need to manually call process_commands()
Listener documentation:
https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.ext.commands.Bot.listen
Examples are provided in both documentation links.
Discord.py on_message breaking rest of commands?
You're modifying message.content
before you pass it to process_commands
; specifically, you're removing all the spaces. Of course none of your command names are going to be matched against a giant, single-word string.
Don't directly modify message.content
. Since you're checking with in
, you don't even need to remove the spaces. Your conditional can also be simplified.
Moreover, as effprime pointed out, if you're going to delete offending messages it doesn't make sense to try to process any commands from them. So you need to either delete the message or process commands from it, not both.
bad_words = ['example1', 'example2', 'example3', 'example4']
if any(word in message.content.lower() for word in bad_words):
await message.delete()
...
else:
await client.process_commands(message)
Related Topics
How to Store the Result of an Executed Shell Command in a Variable in Python
How to Upgrade Python Version to 3.7
Pythonpath Not Working For Sudo on Gnu/Linux (Works For Root)
Change Default Python Version from 2.4 to 2.6
System-Wide Mutex in Python on Linux
Return Value of X = Os.System(..)
Splitting Out the Output of Ps Using Python
Listing Available Devices in Python-Opencv
How to Create a Density Plot in Matplotlib
Converting Epoch Time With Milliseconds to Datetime
Do Python Regular Expressions Have an Equivalent to Ruby'S Atomic Grouping
How to Import a Module Given Its Name as String
Sorting List Based on Values from Another List
What's the Canonical Way to Check For Type in Python
Difference Between Class and Instance Attributes
Link to Flask Static Files With Url_For