YT搜索Discord Bot [英] YT Search on Discord Bot
问题描述
我想知道如何使我的机器人根据YouTube搜索来播放音乐,而不必复制URL。
i would like to know how to make my bot play music based on YouTube search rather than having to copy in a URL.
这是我播放音乐的代码现在,
Here's my code for playing music right now,
@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。
What is it that I need to add to make it play search results instead of URL's.
谢谢!
推荐答案
您可以将 default_search
设置为自动
。这意味着当指定URL时,它仍然可以按预期运行,但是如果不是URL,则将进行搜索。此处的文档: https://github.com/rg3/youtube -dl / blob / master / README.md#options
You can do this by setting default_search
to auto
in the options. This means that it still functions as expected when a URL is specified, but if it's not a URL then a search will be done instead. Documentation here:https://github.com/rg3/youtube-dl/blob/master/README.md#options
在您的代码中,您可以这样修改它。
In your code, you can modify it as such.
@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()
这篇关于YT搜索Discord Bot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!