discord.py-переписать музыку - не может использовать проверку - PullRequest
0 голосов
/ 30 мая 2019

Итак, у меня есть 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 голосов
/ 30 мая 2019

@ 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().

...