【发布时间】:2021-05-12 20:40:09
【问题描述】:
我想让我的机器人从 url 播放音频,但我不想下载文件...
这是我的代码:
@commands.command(name='test')
async def test(self, ctx):
search = "morpheus tutorials discord bot python"
if ctx.message.author.voice == None:
await ctx.send(embed=Embeds.txt("No Voice Channel", "You need to be in a voice channel to use this command!", ctx.author))
return
channel = ctx.message.author.voice.channel
voice = discord.utils.get(ctx.guild.voice_channels, name=channel.name)
voice_client = discord.utils.get(self.client.voice_clients, guild=ctx.guild)
if voice_client == None:
await voice.connect()
else:
await voice_client.move_to(channel)
search = search.replace(" ", "+")
html = urllib.request.urlopen("https://www.youtube.com/results?search_query=" + search)
video_ids = re.findall(r"watch\?v=(\S{11})", html.read().decode())
#################################
await ctx.send("https://www.youtube.com/watch?v=" + video_ids[0])
# AND HERE SHOULD IT PLAY
#################################
我尝试了 create_ytdl_player 方法,但发现它不再支持我该怎么办?
【问题讨论】:
-
你可以看看discord.py github repo中的一个例子,link
-
我正在尝试使用这条线: ctx.voice_client.play(url, after=lambda e: print('Player error: %s' % e) if e else None) 但后来我得到了错误,需要音频源而不是 str
标签: python discord bots discord.py