retrying to connect to the lavalink server until it worked

This commit is contained in:
Mylloon 2021-08-14 15:06:12 +02:00
parent af4ee74b13
commit 4e948545ca

View file

@ -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):