当在discord.py中使用ytdl_player时,我试图将另一首歌曲排队,则出现此错误。我该如何解决?

时间:2019-04-03 14:53:07

标签: python asynchronous discord.py

我正在创建一个discord机器人,在该机器人中,我包括一个播放音乐的命令,还有一个将歌曲排队的命令。当我播放歌曲时,尝试在另一首歌曲排队时,出现以下错误消息,这是我的queue命令代码。


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

预期结果:它可以工作,并且歌曲将在接下来播放。 实际结果:av_interleaved_write_frame():无效的参数                av_interleaved_write_frame():管道损坏                编写管道预告片时出错:1:参数无效                编写管道预告片时出错:1:管道损坏

           Process finished with exit code -1073741819 (0xC0000005)

1 个答案:

答案 0 :(得分: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")

我刚刚创建了一个名为q()的新函数,该函数以比以前更好的方式将下一首歌曲添加到队列中,并且将queues = []也改回了queues = {}