基本上,我希望此命令只能在DMS中运行,并且不能在我的机器人所在的服务器中激活,我知道有一个装饰器可以检查,但是我不确定如何准确地使用它,是否有帮助受到赞赏
class verify:
def check():
#something
@bot.command()
@commands.check(check)
async def verify(ctx):
答案 0 :(得分:0)
编辑:
在我撰写本文后几秒钟,发布了1.1.0版,其中包括内置的dm_only
检查
原文:
这与内置的guild_only
检查(is defined as)相反:
def guild_only():
"""A :func:`.check` that indicates this command must only be used in a
guild context only. Basically, no private messages are allowed when
using the command.
This check raises a special exception, :exc:`.NoPrivateMessage`
that is inherited from :exc:`.CheckFailure`.
"""
def predicate(ctx):
if ctx.guild is None:
raise NoPrivateMessage()
return True
return check(predicate)
因此dm_only
支票看起来像
class NoGuildMessage(CheckFailure):
pass
def dm_only():
def predicate(ctx):
if ctx.guild is not None:
raise NoGuildMessage()
return True
return check(predicate)