There is nothing in the documentation that I could see which said anything about globally disabling events for private messages.
The way you've done it is exactly what I'd do. You say you don't want to repeat the line every time, but you can only have one on_message()
, so that line will only need to appear once; every command that needs to obey those rules will just be in that if
block:
@client.event
async def on_message(message):
if message.server is not None:
if message.content.startswith('!dice'):
...
if message.content.startswith('!roulette'):
...
EDIT: It appears you're using the commands
extension, which is pretty much undocumented.
Reading the docstring for Command
, though, I came across this section:
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.
So if you define your command as such:
@client.command(pass_context=True, no_pm=True)
async def profile(ctx):
...
It will be disabled in PMs.