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 From 5f837400879e1dc87ed0dda9ef0e05b21ca0d3f4 Mon Sep 17 00:00:00 2001 From: Daniel Gu Date: Fri, 28 Apr 2023 22:27:50 +0800 Subject: Update bot/resources/tags/on-message-event.md Co-authored-by: Canttuchdiz <75583497+Canttuchdiz@users.noreply.github.com> --- bot/resources/tags/on-message-event.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/resources/tags/on-message-event.md b/bot/resources/tags/on-message-event.md index f3a0a296c..dde1c7b3b 100644 --- a/bot/resources/tags/on-message-event.md +++ b/bot/resources/tags/on-message-event.md @@ -5,7 +5,7 @@ embed: 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. +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, preventing an override of on_message, and allowing prefix commands to still be invoked. ```python @bot.listen('on_message') -- cgit v1.2.3 From 97efc1c655f9b6553d79cd24351f8030d171c007 Mon Sep 17 00:00:00 2001 From: Daniel Gu Date: Fri, 28 Apr 2023 22:28:02 +0800 Subject: Update bot/resources/tags/on-message-event.md Co-authored-by: Canttuchdiz <75583497+Canttuchdiz@users.noreply.github.com> --- bot/resources/tags/on-message-event.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/resources/tags/on-message-event.md b/bot/resources/tags/on-message-event.md index dde1c7b3b..ae98e1495 100644 --- a/bot/resources/tags/on-message-event.md +++ b/bot/resources/tags/on-message-event.md @@ -3,7 +3,7 @@ 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. +When registering the `on_message` event, 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, preventing an override of on_message, and allowing prefix commands to still be invoked. -- cgit v1.2.3 From 9936d6f998878dbdf3b89133fcb3a111c86d37ab Mon Sep 17 00:00:00 2001 From: Daniel Gu Date: Fri, 28 Apr 2023 22:52:43 +0800 Subject: Update on-message-event.md --- bot/resources/tags/on-message-event.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/resources/tags/on-message-event.md b/bot/resources/tags/on-message-event.md index ae98e1495..35a841f87 100644 --- a/bot/resources/tags/on-message-event.md +++ b/bot/resources/tags/on-message-event.md @@ -3,9 +3,9 @@ embed: title: "The `on_message` event" --- -When registering the `on_message` event, prefix commands may stop working as it overrides the default behaviour of the `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. -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, preventing an override of on_message, and allowing prefix commands to still be invoked. +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, rather than overriding it, so prefix commands can still be invoked as usual: ```python @bot.listen('on_message') -- cgit v1.2.3 From d0ca29eb3d65915336cb6a3218c80cb41452bdc5 Mon Sep 17 00:00:00 2001 From: Daniel Gu Date: Sat, 29 Apr 2023 22:44:55 +0800 Subject: Apply suggestions from code review Co-authored-by: wookie184 --- bot/resources/tags/on-message-event.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/bot/resources/tags/on-message-event.md b/bot/resources/tags/on-message-event.md index 35a841f87..5227db98c 100644 --- a/bot/resources/tags/on-message-event.md +++ b/bot/resources/tags/on-message-event.md @@ -6,13 +6,11 @@ embed: 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. 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, rather than overriding it, so prefix commands can still be invoked as usual: - ```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 -- cgit v1.2.3 From 920994b707fe4edd3b2acedba63253f728c9a1ab Mon Sep 17 00:00:00 2001 From: Daniel Gu Date: Sat, 29 Apr 2023 22:45:05 +0800 Subject: Apply suggestions from code review Co-authored-by: wookie184 --- bot/resources/tags/on-message-event.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/resources/tags/on-message-event.md b/bot/resources/tags/on-message-event.md index 5227db98c..dd3093363 100644 --- a/bot/resources/tags/on-message-event.md +++ b/bot/resources/tags/on-message-event.md @@ -1,6 +1,6 @@ --- embed: - title: "The `on_message` event" + 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. -- cgit v1.2.3 From 3815028b9afd36f83539ca65764ec166c1f0a443 Mon Sep 17 00:00:00 2001 From: Daniel Gu Date: Sat, 29 Apr 2023 22:49:45 +0800 Subject: Remove example of not recommended solution --- bot/resources/tags/on-message-event.md | 8 -------- 1 file changed, 8 deletions(-) diff --git a/bot/resources/tags/on-message-event.md b/bot/resources/tags/on-message-event.md index dd3093363..fe18a453a 100644 --- a/bot/resources/tags/on-message-event.md +++ b/bot/resources/tags/on-message-event.md @@ -13,12 +13,4 @@ async def message_listener(message): ``` 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 From 79e4dfdcd23b6af8fd1e7c6c7a4ea8f44aaa673d Mon Sep 17 00:00:00 2001 From: Daniel Gu Date: Sat, 29 Apr 2023 22:55:27 +0800 Subject: Update on-message-event.md --- bot/resources/tags/on-message-event.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bot/resources/tags/on-message-event.md b/bot/resources/tags/on-message-event.md index fe18a453a..54980c03f 100644 --- a/bot/resources/tags/on-message-event.md +++ b/bot/resources/tags/on-message-event.md @@ -3,7 +3,7 @@ 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. +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` event, rather than overriding it, so prefix commands can still be invoked as usual: ```python @@ -11,6 +11,6 @@ Instead, use [`@bot.listen`](https://discordpy.readthedocs.io/en/stable/ext/comm 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. +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 need the `message_content` intent. See `!tag message_content` for more info. +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. -- cgit v1.2.3 From e136edbfc7026318a000d81c861905cdd0f44af8 Mon Sep 17 00:00:00 2001 From: Daniel Gu Date: Tue, 2 May 2023 11:42:35 +0800 Subject: Update bot/resources/tags/on-message-event.md Co-authored-by: Canttuchdiz <75583497+Canttuchdiz@users.noreply.github.com> --- bot/resources/tags/on-message-event.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bot/resources/tags/on-message-event.md b/bot/resources/tags/on-message-event.md index 54980c03f..b5e6fc6b0 100644 --- a/bot/resources/tags/on-message-event.md +++ b/bot/resources/tags/on-message-event.md @@ -7,9 +7,15 @@ Registering the `on_message` event with [`@bot.event`](https://discordpy.readthe 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, rather than overriding it, so prefix commands can still be invoked as usual: ```python +# Method 1 @bot.listen('on_message') async def message_listener(message): ... # do stuff here + +# Method 2 +@bot.listen() +async def on_message(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. -- cgit v1.2.3 From 2b4c670fd14e70d54892460d49f25e12f855ad6d Mon Sep 17 00:00:00 2001 From: Daniel Gu Date: Tue, 2 May 2023 11:50:37 +0800 Subject: Update on-message-event.md --- bot/resources/tags/on-message-event.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/bot/resources/tags/on-message-event.md b/bot/resources/tags/on-message-event.md index b5e6fc6b0..89c43ff0b 100644 --- a/bot/resources/tags/on-message-event.md +++ b/bot/resources/tags/on-message-event.md @@ -7,16 +7,16 @@ Registering the `on_message` event with [`@bot.event`](https://discordpy.readthe 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, rather than overriding it, so prefix commands can still be invoked as usual: ```python -# Method 1 -@bot.listen('on_message') -async def message_listener(message): - ... # do stuff here - -# Method 2 @bot.listen() async def on_message(message): ... # do stuff here + +# Or... + +@bot.listen('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. +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. -- cgit v1.2.3 From 6f5e62c8d8cf14790e60723a486f75b074734007 Mon Sep 17 00:00:00 2001 From: Daniel Gu Date: Tue, 2 May 2023 22:56:07 +0800 Subject: Update on-message-event.md --- bot/resources/tags/on-message-event.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/resources/tags/on-message-event.md b/bot/resources/tags/on-message-event.md index 89c43ff0b..fd2454eb8 100644 --- a/bot/resources/tags/on-message-event.md +++ b/bot/resources/tags/on-message-event.md @@ -5,7 +5,7 @@ embed: 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` event, rather than overriding it, so prefix commands can still be invoked as usual: +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 @bot.listen() async def on_message(message): -- cgit v1.2.3