Add more autoplay songs when queue gets low

This commit is contained in:
Parker M. 2024-04-12 00:29:42 -05:00
parent 66bf2a6cc2
commit 07f49fa2b7
No known key found for this signature in database
GPG Key ID: 95CD2E0C7E329F2A

View File

@ -9,6 +9,7 @@ from global_variables import (
LAVALINK_PORT, LAVALINK_PORT,
LOG, LOG,
) )
from ai_recommendations import add_song_recommendations
class LavalinkVoiceClient(discord.VoiceProtocol): class LavalinkVoiceClient(discord.VoiceProtocol):
@ -193,6 +194,16 @@ class Music(commands.Cog):
if guild is not None: if guild is not None:
await guild.voice_client.disconnect(force=True) await guild.voice_client.disconnect(force=True)
@lavalink.listener(lavalink.events.TrackEndEvent)
async def on_track_end(self, event: lavalink.events.TrackEndEvent):
guild_id = event.player.guild_id
if len(event.player.queue) <= 10 and guild_id in self.bot.autoplay:
inputs = {}
for song in event.player.queue[:10]:
inputs[song.title] = song.author
await add_song_recommendations(self.bot.user, event.player, 5, inputs)
async def setup(bot): async def setup(bot):
await bot.add_cog(Music(bot)) await bot.add_cog(Music(bot))