From 371eaa8319d324d72a7e49949cbe62fccde34f22 Mon Sep 17 00:00:00 2001 From: n0Oo0Oo0b Date: Fri, 28 Apr 2023 14:13:21 +0800 Subject: Add on-message-event.md --- bot/resources/tags/on-message-event.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 bot/resources/tags/on-message-event.md 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 +@bot.listen('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 +@bot.event +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. -- cgit v1.2.3