From 4a1313f00c813bcd3566ace62167707728a06745 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Sat, 5 Mar 2016 20:10:11 -0500 Subject: [PATCH] [commands] Add when_mentioned_or helper to have mentions and prefixes. --- discord/ext/commands/__init__.py | 2 +- discord/ext/commands/bot.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/discord/ext/commands/__init__.py b/discord/ext/commands/__init__.py index 616e89100..0bf1590e1 100644 --- a/discord/ext/commands/__init__.py +++ b/discord/ext/commands/__init__.py @@ -10,7 +10,7 @@ An extension module to facilitate creation of bot commands. :license: MIT, see LICENSE for more details. """ -from .bot import Bot, when_mentioned +from .bot import Bot, when_mentioned, when_mentioned_or from .context import Context from .core import * from .errors import * diff --git a/discord/ext/commands/bot.py b/discord/ext/commands/bot.py index 3f4559d23..1c3885046 100644 --- a/discord/ext/commands/bot.py +++ b/discord/ext/commands/bot.py @@ -51,6 +51,27 @@ def when_mentioned(bot, msg): to being mentioned, e.g. ``@bot ``.""" return '{0.user.mention} '.format(bot) +def when_mentioned_or(*prefixes): + """A callable that implements when mentioned or other prefixes provided. + + Examples + --------- + + .. code-block:: python + + bot = commands.Bot(command_prefix=commands.when_mentioned_or('!')) + + See Also + ---------- + :func:`when_mentioned` + """ + def inner(bot, msg): + r = list(prefixes) + r.append('{0.user.mention} '.format(bot)) + return r + + return inner + @asyncio.coroutine def _default_help_command(ctx, *commands : str): """Shows this message."""