-
-
Notifications
You must be signed in to change notification settings - Fork 751
on-message-event tag #2567
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+22
−0
Merged
on-message-event tag #2567
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
371eaa8
Add on-message-event.md
n0Oo0Oo0b 5f83740
Update bot/resources/tags/on-message-event.md
97efc1c
Update bot/resources/tags/on-message-event.md
9936d6f
Update on-message-event.md
n0Oo0Oo0b d0ca29e
Apply suggestions from code review
n0Oo0Oo0b 920994b
Apply suggestions from code review
n0Oo0Oo0b 3815028
Remove example of not recommended solution
n0Oo0Oo0b 79e4dfd
Update on-message-event.md
n0Oo0Oo0b 9deff0f
Merge branch 'main' into on-message-event-tag
e136edb
Update bot/resources/tags/on-message-event.md
n0Oo0Oo0b 2b4c670
Update on-message-event.md
n0Oo0Oo0b 6f5e62c
Update on-message-event.md
n0Oo0Oo0b 6896055
Merge branch 'main' into on-message-event-tag
6156440
Merge branch 'main' into on-message-event-tag
shtlrs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
| @bot.listen() | ||
| async def on_message(message): | ||
| ... # do stuff here | ||
|
|
||
| # Or... | ||
|
|
||
| @bot.listen('on_message') | ||
| async def message_listener(message): | ||
|
n0Oo0Oo0b marked this conversation as resolved.
|
||
| ... # 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. | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.