【发布时间】:2019-05-30 23:19:41
【问题描述】:
所以,我有一个 Discord BOT,其音乐齿轮如下所示:
def setup(bot):
class Music:
__slots__ = ("players", )
def __init__(self):
self.players = {}
def get_player(self, ctx):
# Retrieve the guild player.
def check_player(self):
def predicate(ctx):
# PREVIOUS CHECK
player = self.get_player(ctx)
# CHECK PLAYER STATE
return commands.check(predicate)
@commands.command()
@check_player(self)
async def a_command(self, ctx):
pass
bot.add_cog(Music())
但我不能使用check_player() 检查a_command() 命令,因为self 未定义。有人知道我该如何解决这个问题吗?
【问题讨论】:
-
您需要将您的检查定义为一个只接受
ctx的函数。它不能是您的 cog 方法或依赖于self。 (因为检查的回调只注册一次,对于类的所有实例)。支票检查是什么? -
get_player是如何工作的?此行为可能无法进入check,它们主要用于您可以针对调用上下文进行的快速验证。
标签: python-3.x discord discord.py discord.py-rewrite