When using ytdl_player in discord.py, and i am trying to queue another song, i get this error. How do i fix this?

0

I am creating a discord bot, and in this bot I am including a command that plays music, I also have a command to queue songs. When I am playing a song, and I try to queue another, I get the error message below, this is my code for the queue command.


import discord
from discord.ext import commands
from chat import *

players = {}
queues = {}

def check_queue(id):
    if queues[id] != []:
        player = queues[id].pop(0)
        players[id] = player
        player.start()

@commands.command(pass_context=True)
    async def play(self, ctx):

        channel = ctx.message.author.voice.voice_channel
        url = ctx.message.content
        abc = url[5:]
        server = ctx.message.server
        if self.bot.voice_client_in(server):
            await self.bot.say("queued")
            pass

        else:
            await self.bot.join_voice_channel(channel)
        server = ctx.message.server
        voice_client = self.bot.voice_client_in(server)

        player = await voice_client.create_ytdl_player(abc, ytdl_options={'default_search': 'auto'}, before_options="-reconnect 1 -reconnect_streamed 1 " "-reconnect_delay_max 5", after=lambda: check_queue(server.id))

        players[server.id] = player
        await self.bot.say("now playing" + abc)
        player.start()

Expected result: It works, and the song queues to be played next. actual result: av_interleaved_write_frame(): Invalid argument av_interleaved_write_frame(): Broken pipe Error writing trailer of pipe:1: Invalid argument Error writing trailer of pipe:1: Broken pipe

           Process finished with exit code -1073741819 (0xC0000005)
python
asynchronous
discord.py
asked on Stack Overflow Apr 3, 2019 by TheRoaster

1 Answer

0
if self.bot.voice_client_in(server):
            await self.q(ctx, abc)

async def q(self, ctx, url):
    server = ctx.message.server
    voice_client = self.bot.voice_client_in(server)
    player = await voice_client.create_ytdl_player(url, ytdl_options={'default_search': 'auto'}, after=lambda: check_queue(server.id))

    if server.id in queues:
        queues[server.id].append(player)
    else:
        queues[server.id] = [player]
    await self.bot.say("queued")

I just made a new function called q(), which added next song to queue in a better way than before, changed queues = [] back into queues = {} aswell

answered on Stack Overflow Apr 3, 2019 by TheRoaster • edited Apr 4, 2019 by anki

User contributions licensed under CC BY-SA 3.0