我在 discord.py 中创建了 youtube 搜索命令,但由于某种原因,机器人只发送 youtube 的主页,而不是我想搜索的词。
我的代码:
@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])
答案 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])