discord.py-重写音乐-无法使用检查

时间:2019-05-30 15:00:09

标签: python-3.x discord discord.py discord.py-rewrite

所以,我有一个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检查。任何人都知道我该如何解决?

1 个答案:

答案 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()检查的工作方式。