I built a discord bot using discord.py and ffmpeg, it works but the song in the first 0-5 seconds plays too fast, I think it's buffering so I tried to use asyncio.sleep but didn't work, suggestions to solve the problem?
play func:
with youtube_dl.YoutubeDL(self.opts) as ydl:
await asyncio.sleep(0.1)
ydl.cache.remove()
await asyncio.sleep(0.1)
info = ydl.extract_info(url, download=False)
raw_url_song = info['formats'][0]['url']
await self.real_play(ctx, raw_url_song)
real_play func:
source = await discord.FFmpegOpusAudio.from_probe(processed_url_song, **self.FFMPEG_OPTIONS)
await asyncio.sleep(0.5)
self.vc.play(source, after=lambda e: asyncio.run_coroutine_threadsafe(self.real_play(ctx, processed_url_song), self.client.loop))
these are the options:
self.FFMPEG_OPTIONS = {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5', 'options': '-vn'}
self.OPTIONS = {'format': 'bestaudio'}
self.opts = {'extract_flat': True, 'skip_download': True}
the functions are separate because I do something else (such as playlists), I have reported only the essential code to understand the problem, and the cache remove is essential to reduce the occurence of HTTP 404 forbidden error, btw also without cache remove the problem persists
I've added a pause() and resume() function with a sleep function inside it. It works but it takes a second.
import asyncio
voice = bot.voice_clients[0]
voice.play(discord.FFmpegPCMAudio("song.mp3"))
voice.pause()
await asyncio.sleep(1)
voice.resume()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With