Как я могу зациклить всю очередь песни вместо одной песни? - PullRequest
0 голосов
/ 10 ноября 2019

Так что мне нужно знать, как сделать цикл команды loop все добавленные песни вместо только текущей песни.

Я попытался зациклить класс SongQueue, но мне кажется, что я делаю это неправильно

class SongQueue(asyncio.Queue):
    def __getitem__(self, item):
        if isinstance(item, slice):
            return list(itertools.islice(self._queue, item.start, item.stop, item.step))
        else:
            return self._queue[item]

    def __iter__(self):
        return self._queue.__iter__()

    def __len__(self):
        return self.qsize()

    def clear(self):
        self._queue.clear()

    def shuffle(self):
        random.shuffle(self._queue)

    def remove(self, index: int):
        del self._queue[index]

#--Now for the loop command:--
    @commands.command(name='loop')
    async def _loop(self, ctx: commands.Context):
        """Loops the currently playing song.
        Invoke this command again to unloop the song.
        """

        if not ctx.voice_state.is_playing:
            return await ctx.send('Nothing being played at the moment.')

        # Inverse boolean value to loop and unloop.
        ctx.voice_state.loop = not ctx.voice_state.loop
        await ctx.message.add_reaction('✅')

Полный код с открытым исходным кодом здесь: https://gist.github.com/vbe0201/ade9b80f2d3b64643d854938d40a0a2d#file-music_bot_example-py-L1. Я все еще пытаюсь изучить Python, поэтому я предполагаю, что это довольно просто.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...