Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 不和谐机器人上的YT搜索_Python_Discord_Discord.py - Fatal编程技术网

Python 不和谐机器人上的YT搜索

Python 不和谐机器人上的YT搜索,python,discord,discord.py,Python,Discord,Discord.py,我想知道如何让我的机器人播放基于YouTube搜索的音乐,而不必复制URL 这是我现在播放音乐的代码 @client.command(pass_context=True) async def play(ctx, url): server = ctx.message.server await client.say ('Music now playing...') voice_client = client.voice_client_in(server)

我想知道如何让我的机器人播放基于YouTube搜索的音乐,而不必复制URL

这是我现在播放音乐的代码

  @client.command(pass_context=True)
     async def play(ctx, url):
    server = ctx.message.server
    await client.say ('Music now playing...')
    voice_client = client.voice_client_in(server)
    player = await voice_client.create_ytdl_player(url, after=lambda: 
    check_queue(server.id))
    players[server.id] = player
    player.start()
我需要添加什么来让它播放搜索结果而不是URL


谢谢

您可以通过在选项中将
default\u search
设置为
auto
来完成此操作。这意味着,当指定URL时,它仍按预期运行,但如果它不是URL,则将执行搜索。此处的文档:

在代码中,您可以对其进行修改

@client.command(pass_context=True)
    async def play(ctx, url):
    server = ctx.message.server
    await client.say ('Music now playing...')
    voice_client = client.voice_client_in(server)
    player = await voice_client.create_ytdl_player(url, ytdl_options={'default_search': 'auto'} after=lambda: check_queue(server.id))
    players[server.id] = player
    player.start()