From b98a8c1e14c1cf496debe8ec7002507b38ec4dc0 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Fri, 22 Jan 2016 07:21:40 -0500 Subject: [PATCH] [commands] Add Command.no_pm attribute to block a command in PM. --- discord/ext/commands/core.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/discord/ext/commands/core.py b/discord/ext/commands/core.py index 5e5ba7953..5ab98539e 100644 --- a/discord/ext/commands/core.py +++ b/discord/ext/commands/core.py @@ -98,6 +98,11 @@ class Command: hidden : bool If ``True``, the default help command does not show this in the help output. + no_pm : bool + If ``True``, then the command is not allowed to be executed in + private messages. Defaults to ``False``. Note that if it is executed + in private messages, then :func:`on_command_error` and local error handlers + are called with the :exc:`NoPrivateMessage` error. rest_is_raw : bool If ``False`` and a keyword-only argument is provided then the keyword only argument is stripped and handled as if it was a regular argument @@ -121,6 +126,7 @@ class Command: self.params = signature.parameters.copy() self.checks = kwargs.get('checks', []) self.module = inspect.getmodule(callback) + self.no_pm = kwargs.get('no_pm', False) self.instance = None self.parent = None @@ -303,6 +309,10 @@ class Command: try: if not self.enabled: raise DisabledCommand('{0.name} command is disabled'.format(self)) + + if self.no_pm and ctx.message.channel.is_private: + raise NoPrivateMessage('This command cannot be used in private messages.') + if not self.can_run(ctx): raise CheckFailure('The check functions for command {0.name} failed.'.format(self)) except CommandError as exc: