GodecBot
GodecBot copied to clipboard
Autoplay not working
Autoplay doesn't work, meaning that after the last song in the queue has finished, it doesn't play any suggested songs, and doesn't give any errors.
I worked out that one of the problems was from when it defines the soup object in the voice class, as I hadn't pip installed lxml. However, It is now seeming to get stuck at:
recommended_urls = []
for li in soup.find_all('li', class_='related-list-item'):
a = li.find('a')
I think this is due to soup.find_all('li', class_=related-list-item'):
returning None
@nose-gnome @Lenart12 did you find any solution for the autoplay.
Didn't know this bot was in use still, I will take a look
Ok so i got the autoplay working as i wanted but now after playing one song it autoplays another song then stops after that not playing anymore songs even if i use -play command it only queues so my guess is that the bit gets stuck somewhere in that loop so is there anyway i can make it continuosly play songs automatically.
async def audio_player_task(self):
while True:
self.next.clear()
self.now = None
if self.loop == False:
# If autoplay is turned on wait 3 seconds for a new song.
# If no song is found find a new one,
# else if autoplay is turned off try to get the
# next song within 3 minutes.
# If no song will be added to the queue in time,
# the player will disconnect due to performance
# reasons.
if self.autoplay and self.current:
try:
async with timeout(3):
self.current = await self.songs.get()
except asyncio.TimeoutError:
# Spoof user agent to show whole page.
song_url = self.current.source.url
# Get the page
html = urllib.request.urlopen(song_url)
video_ids = re.findall(r"watch\?v=(\S{11})", html.read().decode())
ol = []
ov = []
length = len(video_ids)
for i in range(length):
song = f'https://www.youtube.com/watch?v={video_ids[i]}'
if song == song_url:
pass
else:
if song not in ol:
ol.append(song)
ol = ol[:10]
for j in ol:
vid = pafy.new(j)
val = vid.viewcount
ov.append(int(val))
max_value = max(ov)
max_index = ov.index(max_value)
# Parse all the recommended videos out of the response and store them in a list
ctx = self._ctx
# Chose the next song so that it wasnt played recently
next_song = ol[max_index]
async with ctx.typing():
try:
source = await ytdl.YTDLSource.create_source(ctx, next_song, loop=self.bot.loop)
except ytdl.YTDLError as e:
await ctx.send('An error occurred while processing this request: {}'.format(str(e)))
self.bot.loop.create_task(self.stop())
self.exists = False
return
else:
song = Song(source)
self.current = song
self.voice.play(self.current.source, after=self.play_next_song())
await ctx.send('Autoplaying {}'.format(str(source)))
else:
try:
async with timeout(180): # 3 minutes
self.current = await self.songs.get()
except asyncio.TimeoutError:
self.bot.loop.create_task(self.stop())
self.exists = False
return
await asyncio.sleep(1)
await self.current.source.channel.send("Playing next song...")
self.song_history.insert(0, self.current)
self.current.source.volume = self._volume
self.voice.play(self.current.source, after=self.play_next_song)
await self.current.source.channel.send(embed=self.current.create_embed())
# If the song is looped
elif self.loop == True:
self.song_history.insert(0, self.current)
self.now = discord.FFmpegPCMAudio(self.current.source.stream_url, **ytdl.YTDLSource.FFMPEG_OPTIONS)
self.voice.play(self.now, after=self.play_next_song)
await self.next.wait()
here is my code