Не исполняется код после строчки "подключения к голосовому чату"
Подскажите знающие люди почему после команды "await ctx.author.voice.channel.connect()" (6-я строка) дальнейший код программы не исполняется и можно ли это как-то избежать. Задумка такая, что при вызове пользовательской команды !play бот подключится к голосовому чату и начнет воспроизведение. Но в данном случае, он только подключается к каналу и останавливается.
@commands.command()
async def play(self, ctx, url):
if ctx.author.voice is None:
return await ctx.send(
"You are not connected to a voice channel, please connect to the channel you want the bot to join.")
await ctx.author.voice.channel.connect()
if url is None:
return await ctx.send("You must include a song to play.")
if ctx.voice_client is None:
return await ctx.send("I must be in a voice channel to play a song.")
if ctx.voice_client.source is None and self.song_queue[ctx.guild.id] == []:
ctx.voice_client.stop()
FFMPEG_OPTIONS = {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5',
'options': '-vn'}
YDL_OPTIONS = {'format': 'bestaudio', 'noplaylist': 'False'}
vc = ctx.voice_client
with youtube_dl.YoutubeDL(YDL_OPTIONS) as ydl:
info = ydl.extract_info(url, download=False)
url2 = info['formats'][0]['url']
source = await discord.FFmpegOpusAudio.from_probe(url2, **FFMPEG_OPTIONS)
vc.play(source, after=lambda error: self.bot.loop.create_task(self.check_queue(ctx, ctx.guild.id)))
elif ctx.voice_client.source is not None:
queue_len = len(self.song_queue[ctx.guild.id])
if queue_len < 10:
self.song_queue[ctx.guild.id].append(url)
print(self.song_queue)
return await ctx.send(
f"I am currently playing a song, this song has been added to the queue at position: {queue_len + 1}.")
else:
return await ctx.send(
"Sorry, I can only queue up to 10 songs, please wait for the current song to finish.")