diff options
| author | Rapptz <[email protected]> | 2021-03-28 21:21:09 -0400 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2021-03-28 21:21:09 -0400 |
| commit | 862d509d2e39f9d550ec3dff1e7d08fc6b3b5b8d (patch) | |
| tree | f7eafbe4baf8aafc93d41b52b6be44b34299db49 | |
| parent | [commands] Remove nullability from help command implementation (diff) | |
| download | discord.py-862d509d2e39f9d550ec3dff1e7d08fc6b3b5b8d.tar.xz discord.py-862d509d2e39f9d550ec3dff1e7d08fc6b3b5b8d.zip | |
[commands] Add support for stripping whitespace after the prefix
This is configured with the strip_after_prefix option in `Bot.__init__`
| -rw-r--r-- | discord/ext/commands/bot.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/discord/ext/commands/bot.py b/discord/ext/commands/bot.py index a4e74125..ee0308e2 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 |