diff --git a/src/cogs/music.py b/src/cogs/music.py index 4431a24..6a3ad72 100644 --- a/src/cogs/music.py +++ b/src/cogs/music.py @@ -27,6 +27,8 @@ import re import typing import wavelink from discord.ext import commands, menus +from time import sleep +import socket # Genius API from lyricsgenius import Genius @@ -355,8 +357,17 @@ class Music(commands.Cog, wavelink.WavelinkMixin): 'region': self.keys["REGION_DISCORD"] }} - for n in nodes.values(): - await self.bot.wavelink.initiate_node(**n) + nodeValues = list(nodes.values()) + n = 0 + while n < len(nodeValues): + location = (nodeValues[n]["host"], nodeValues[n]["port"]) + a_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + + if a_socket.connect_ex(location) == 0: + await self.bot.wavelink.initiate_node(**nodeValues[n]) # Port is open, connecting... + n += 1 + else: + sleep(1) # Port is not open, retrying in 1 second... @wavelink.WavelinkMixin.listener() async def on_node_ready(self, node: wavelink.Node):