aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Amrou Bellalouna <[email protected]>2023-05-15 15:53:48 +0100
committerGravatar GitHub <[email protected]>2023-05-15 15:53:48 +0100
commitaf79b3c322ebafcded14b18918667d066da8a8d8 (patch)
tree4fd13214b5efd2a5afe631fa117cc779baea94d4
parentBump sentry-sdk from 1.22.0 to 1.22.2 (#2585) (diff)
parentMerge branch 'main' into on-message-event-tag (diff)
Merge pull request #2567 from n0Oo0Oo0b/on-message-event-tag
on-message-event tag
-rw-r--r--bot/resources/tags/on-message-event.md22
1 files changed, 22 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..fd2454eb8
--- /dev/null
+++ b/bot/resources/tags/on-message-event.md
@@ -0,0 +1,22 @@
+---
+embed:
+ title: "The discord.py `on_message` event"
+---
+
+Registering the `on_message` event with [`@bot.event`](https://discordpy.readthedocs.io/en/stable/ext/commands/api.html#discord.ext.commands.Bot.event) will override the default behavior of the event. This may cause prefix commands to stop working, because they rely on the default `on_message` event handler.
+
+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` handler which allows you to have multiple handlers for the same event. This means prefix commands can still be invoked as usual. Here's an example:
+```python
+async def on_message(message):
+ ... # do stuff here
+
+# Or...
+
[email protected]('on_message')
+async def message_listener(message):
+ ... # do stuff here
+```
+You can also tell discord.py to process the message for commands as usual at the end of the `on_message` handler 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.
+
+If your prefix commands are still not working, it may be because you haven't enabled the `message_content` intent. See `/tag message_content` for more info.