diff options
author | 2023-04-28 14:13:21 +0800 | |
---|---|---|
committer | 2023-04-28 14:13:21 +0800 | |
commit | 371eaa8319d324d72a7e49949cbe62fccde34f22 (patch) | |
tree | 0c0a84be6a14ef4781b68f002b7f6f7c87fe4c3b | |
parent | Merge pull request #2554 from python-discord/update-docker-compose (diff) |
Add on-message-event.md
-rw-r--r-- | bot/resources/tags/on-message-event.md | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/bot/resources/tags/on-message-event.md b/bot/resources/tags/on-message-event.md new file mode 100644 index 000000000..f3a0a296c --- /dev/null +++ b/bot/resources/tags/on-message-event.md @@ -0,0 +1,26 @@ +--- +embed: + title: "The `on_message` event" +--- + +When defining an `on_message` event handler, prefix commands may stop working as it overrides the default behaviour of the `on_message` event. + +Instead, use [`@bot.listen`](https://discordpy.readthedocs.io/en/stable/ext/commands/api.html#discord.ext.commands.Bot.listen) to add a listener. Listeners get added alongside the default `on_message` event which allows you to respond to message events and prefix commands at the same time. + +```python [email protected]('on_message') +async def message_listener(message): + ... # do stuff here +``` + +You can also tell discord.py to process commands as usual after you're done processing messages with [`bot.process_commands()`](https://discordpy.readthedocs.io/en/stable/ext/commands/api.html#discord.ext.commands.Bot.process_commands). However, this method isn't recommended as it does not allow you to add multiple `on_message` handlers. + +```python +async def on_message(message): + ... # do stuff here + + await bot.process_commands(message) +``` + +If your prefix commands are still not working, it may be because you need the `message_content` intent. See `!tag message_content` for more info. |