Esempio n. 1
0
    async def play_from_list(self, ctx, *, playlist_name):
        songlist = fileRead.play_playlist(ctx, playlist_name)
        if songlist == False:
            return await ctx.channel.send("Playlist not found.")

        member = utils.find(
            lambda m: m.id == ctx.author.id, ctx.guild.members
        )  # This will connect the bot if it is not already connected, updated and more efficient.
        if member is not None and member.voice is not None:
            vc = member.voice.channel
            player = self.bot.music.player_manager.create(
                ctx.guild.id, endpoint=str(ctx.guild.region))
            if not player.is_connected:
                player.store('channel', ctx.channel.id)
                await self.connect_to(ctx.guild.id, str(vc.id))

            if player.is_connected and not ctx.author.voice.channel.id == int(
                    player.channel_id
            ):  #Make sure the person is in the same chat as the bot to add to queue.
                return await ctx.channel.send(
                    "Please connect to the same chat as the bot.")

            for query in songlist:
                try:
                    if ctx.author.voice is not None:
                        query = f'ytsearch:{query}'
                        results = await player.node.get_tracks(query)
                        try:
                            track = results['tracks'][0]
                            player.add(requester=ctx.author.id, track=track)
                            if not player.is_playing:
                                await player.play()

                        except:
                            await ctx.channel.send(
                                "Song not found. (or title has emojis/symbols)"
                            )

                except Exception as error:
                    print(error)

            await ctx.channel.send("Playlist added to queue.")
        else:
            return await ctx.channel.send(
                "Please join a voice chat to play the playlist.")
Esempio n. 2
0
    async def play_from_list(self, ctx, *, playlist_name):
        """ Searches and plays a song from a given query. """
        # Get the player for this guild from cache.
        songlist = fileRead.play_playlist(ctx, playlist_name)
        if songlist == False:
            return await ctx.channel.send("Playlist not found.")

        player = self.bot.lavalink.player_manager.get(ctx.guild.id)
        # This is to play a song up front so you dont have to wait for whole queue to hear music
        #Need to use this in a try catch to make the player disconnect or something.
        query = songlist[0]
        songlist.pop(0)
        query = f'ytsearch:{query}'
        results = await player.node.get_tracks(query)
        track = results['tracks'][0]
        track = lavalink.models.AudioTrack(track,
                                           ctx.author.id,
                                           recommended=True)
        player.add(requester=ctx.author.id, track=track)

        if not player.is_playing:
            await player.play()

        for track in songlist:  # Add all remaining songs to list.
            try:
                query = f'ytsearch:{track}'
                results = await player.node.get_tracks(query)
                track = results['tracks'][0]
                track = lavalink.models.AudioTrack(track,
                                                   ctx.author.id,
                                                   recommended=True)
                player.add(requester=ctx.author.id, track=track)
            except Exception as error:  # Catches song not found
                print(error)

        await ctx.send(str(playlist_name) + " loaded successfully.")

        if not player.is_playing:
            await player.play()