什么是KeyError:“ twoColumnSearchResultsRenderer”Python,youtube_dl

问题描述

我一直在使用discord.py版本1.5.0用Python编写discord机器人。直到最近,我才开始使用youtube_dl,youtube_search和ffmpeg向其中添加音乐命令。我可以完全播放音频,还可以播放标题,时长,缩略图等。到目前为止,我唯一遇到的问题是,当我将Youtube URL存储在列表中,然后在“ next”命令上对其进行索引时,返回错误消息“ KeyError:'twoColumnSearchResultsRenderer'”,我无法找到将其返回给用户的任何其他示例。如果有人可以帮助我了解问题所在,那么将不胜感激。

编辑:

@bot.command()
    async def play(ctx,*args):
        #local variables
        global queueList
        server = ctx.message.guild
        voiceChannel = server.voice_client
        keywords = listtostring(args)
        results = ast.literal_eval(YoutubeSearch(keywords,max_results=1).to_json())
        test = results['videos']
        print(test[0])
        vidId = test[0]['id']
        vidThumbnail = test[0]['thumbnails'][0]
        vidUrl = "https://www.youtube.com/watch?v={}".format(vidId)
        queueList.append(vidUrl)

        if args and ctx.message.author.voice:

            async with ctx.typing():

                player = await YTDLSource.from_url(queueList[0],loop=client.loop)
                await ctx.send("`{}` added to the queue!".format(player.title))

                try: 
                    voiceChannel.play(player,after=lambda e: print('Player error: %s' % e) if e else None)
                    NowPlaying = discord.Embed(
                        title = "Now playing",description = "Now playing **{}**".format(player.title),color = rupertColor
                    )
                    NowPlaying.set_thumbnail(url=vidThumbnail)

                    await ctx.send(embed = NowPlaying) #('**Now playing:** {}'.format(player.title))
                except: 
                    print("Failed playing")

                del(queueList[0])

        else:
            await stop(ctx)
            async with ctx.typing():
                player = await YTDLSource.from_url(str(queueList[0]),loop=client.loop)
                try: 
                    voiceChannel.play(player,after=lambda e: print('Player error: %s' % e) if e else None)
                    await ctx.send('**Now playing:** {}'.format(player.title))
                except: 
                    print("Failed playing")
                    queueList.append(vidUrl)

                del(queueList[0])

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)