mirror of
https://github.com/Matthww/TuneBot.git
synced 2026-09-21 22:47:51 +00:00
decoupled lavalink creation from cogs.music
This commit is contained in:
+4
-18
@@ -76,25 +76,11 @@ class LavalinkVoiceClient(discord.VoiceClient):
|
||||
class Music(BaseCog):
|
||||
@commands.Cog.listener()
|
||||
async def on_ready(self):
|
||||
if not hasattr(
|
||||
self.bot, "lavalink"
|
||||
): # This ensures the client isn't overwritten during cog reloads.
|
||||
self.bot.lavalink = lavalink.Client(self.bot.user.id)
|
||||
|
||||
ll = self.bot.config["lavalink"]
|
||||
self.bot.lavalink.add_node(
|
||||
ll["host"], ll["port"], ll["password"], ll["region"], ll["name"]
|
||||
)
|
||||
|
||||
self.bot.lavalink.add_event_hook(self.track_hook)
|
||||
await self.async_init()
|
||||
|
||||
async def async_init(self):
|
||||
redis_result = await AutoJoin.get_channels(self.bot._redis_client)
|
||||
|
||||
while len(self.bot.lavalink.node_manager.available_nodes) == 0:
|
||||
while not self.is_lavalink_ready():
|
||||
await asyncio.sleep(1)
|
||||
|
||||
self.bot.lavalink.add_event_hook(self.track_hook)
|
||||
redis_result = await AutoJoin.get_channels(self.bot._redis_client)
|
||||
for guild_id, (voicechannel_id, textchannel_id) in redis_result.items():
|
||||
player = self.bot.lavalink.player_manager.create(guild_id)
|
||||
player.store("channel", textchannel_id)
|
||||
@@ -153,7 +139,7 @@ class Music(BaseCog):
|
||||
# This is essentially the same as `@commands.guild_only()`
|
||||
# except it saves us repeating ourselves (and also a few lines).
|
||||
|
||||
if not hasattr(self.bot, "lavalink"):
|
||||
if not self.is_lavalink_ready():
|
||||
await ctx.send("Still starting please wait a moment.")
|
||||
|
||||
if guild_check:
|
||||
|
||||
Reference in New Issue
Block a user