mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-06-08 04:38:42 +00:00
[commands] Add Command.no_pm attribute to block a command in PM.
This commit is contained in:
parent
2d413756b0
commit
b98a8c1e14
@ -98,6 +98,11 @@ class Command:
|
|||||||
hidden : bool
|
hidden : bool
|
||||||
If ``True``, the default help command does not show this in the
|
If ``True``, the default help command does not show this in the
|
||||||
help output.
|
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
|
rest_is_raw : bool
|
||||||
If ``False`` and a keyword-only argument is provided then the keyword
|
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
|
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.params = signature.parameters.copy()
|
||||||
self.checks = kwargs.get('checks', [])
|
self.checks = kwargs.get('checks', [])
|
||||||
self.module = inspect.getmodule(callback)
|
self.module = inspect.getmodule(callback)
|
||||||
|
self.no_pm = kwargs.get('no_pm', False)
|
||||||
self.instance = None
|
self.instance = None
|
||||||
self.parent = None
|
self.parent = None
|
||||||
|
|
||||||
@ -303,6 +309,10 @@ class Command:
|
|||||||
try:
|
try:
|
||||||
if not self.enabled:
|
if not self.enabled:
|
||||||
raise DisabledCommand('{0.name} command is disabled'.format(self))
|
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):
|
if not self.can_run(ctx):
|
||||||
raise CheckFailure('The check functions for command {0.name} failed.'.format(self))
|
raise CheckFailure('The check functions for command {0.name} failed.'.format(self))
|
||||||
except CommandError as exc:
|
except CommandError as exc:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user