Skip to content
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

[commands] Add option to process a certain command_str #9279

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion discord/ext/commands/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1358,7 +1358,7 @@ async def invoke(self, ctx: Context[BotT], /) -> None:
exc = errors.CommandNotFound(f'Command "{ctx.invoked_with}" is not found')
self.dispatch('command_error', ctx, exc)

async def process_commands(self, message: Message, /) -> None:
async def process_commands(self, message: Message, *, command_str: Optional[str] = MISSING) -> None:
"""|coro|

This function processes the commands that have been registered
Expand All @@ -1383,11 +1383,20 @@ async def process_commands(self, message: Message, /) -> None:
-----------
message: :class:`discord.Message`
The message to process commands for.
command_str: Optional[:class:`str`]
The command string which should be processed.
This can be useful to process multiple commands.
"""
if message.author.bot:
return

before_content = message.content
if command_str not in (MISSING, None):
message.content = command_str

ctx = await self.get_context(message)
message.content = before_content

# the type of the invocation context's bot attribute will be correct
await self.invoke(ctx) # type: ignore

Expand Down