所以,我有一个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
检查。任何人都知道我该如何解决?
答案 0 :(得分:0)
@PatrickHaugh
def get_player(self, ctx):
"""Retrieve the guild player, or generate one."""
try:
player = self.players[ctx.guild.id]
except KeyError:
player = MusicPlayer(ctx, bot)
self.players[ctx.guild.id] = player
except:
return None
return player
这是get_player()
检查的工作方式。