Youtube 搜索命令不起作用 (Discord.py)

时间:2021-01-21 13:43:30

标签: python pycharm discord.py

我在 discord.py 中创建了 youtube 搜索命令,但由于某种原因,机器人只发送 youtube 的主页,而不是我想搜索的词。

enter image description here

我的代码:

@bot.command()
@commands.cooldown(1, 60.00, commands.BucketType.guild)
async def yt(msg, *, search):
    query_string = urllib.parse.urlencode({
        "search_query": search
    })
    html_content = urllib.request.urlopen(
        "http://www.youtube.com/results?" + query_string
    )
    search_results = re.findall(r"watch\?v=(\S{11})", html_content.read().decode())
    await msg.send("http://www.youtube.com/watch?v" + search_results[0])

1 个答案:

答案 0 :(得分:0)

改变这个:

await msg.send("http://www.youtube.com/watch?v" + search_results[0])

为此:

await msg.send("http://www.youtube.com/watch?v=" + search_results[0])
相关问题