From 862d509d2e39f9d550ec3dff1e7d08fc6b3b5b8d Mon Sep 17 00:00:00 2001 From: Rapptz Date: Sun, 28 Mar 2021 21:21:09 -0400 Subject: [PATCH] [commands] Add support for stripping whitespace after the prefix This is configured with the strip_after_prefix option in `Bot.__init__` --- discord/ext/commands/bot.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/discord/ext/commands/bot.py b/discord/ext/commands/bot.py index a4e74125b..ee0308e28 100644 --- a/discord/ext/commands/bot.py +++ b/discord/ext/commands/bot.py @@ -108,6 +108,7 @@ class BotBase(GroupMixin): self.description = inspect.cleandoc(description) if description else '' self.owner_id = options.get('owner_id') self.owner_ids = options.get('owner_ids', set()) + self.strip_after_prefix = options.get('strip_after_prefix', False) if self.owner_id and self.owner_ids: raise TypeError('Both owner_id and owner_ids are set.') @@ -911,6 +912,9 @@ class BotBase(GroupMixin): # Getting here shouldn't happen raise + if self.strip_after_prefix: + view.skip_ws() + invoker = view.get_word() ctx.invoked_with = invoker ctx.prefix = invoked_prefix @@ -1041,6 +1045,12 @@ class Bot(BotBase, discord.Client): for the collection. You cannot set both ``owner_id`` and ``owner_ids``. .. versionadded:: 1.3 + strip_after_prefix: :class:`bool` + Whether to strip whitespace characters after encountering the command + prefix. This allows for ``! hello`` and ``!hello`` to both work if + the ``command_prefix`` is set to ``!``. Defaults to ``False``. + + .. versionadded:: 1.7 """ pass