def create_voice_client(self, channel):
"""Creates a voice client and saves it"""
# First join the channel and get the VoiceClient that we'll use to save per server
await self.remove_voice_client(channel.server)
server = channel.server
state = self.get_voice_state(server)
voice = self.bot.voice_client_in(server)
# Attempt 3 times
for i in range(3):
try:
if voice is None:
state.voice = await self.bot.join_voice_channel(channel)
if state.voice:
return True
elif voice.channel == channel:
state.voice = voice
return True
else:
# This shouldn't theoretically ever happen yet it does. Thanks Discord
await voice.disconnect()
state.voice = await self.bot.join_voice_channel(channel)
if state.voice:
return True
except (discord.ClientException, socket.gaierror, ConnectionResetError):
continue
return False
评论列表
文章目录