def connect(self, data):
"""
Connect to a channel in the specific server, or move if already in vc
:param: false or default channel id
:param data: message data to get author out of
:return: True if connected, False if something went wrong
"""
try:
m_channel = self.parent.channel_manager.get_channel(self.guild, "voice_music")
except ChannelNotFoundError:
m_channel = None
except AttributeError:
self.parent.logger.error("Failed to get channel.")
m_channel = None
if not m_channel and data.author.voice and data.author.voice.channel:
m_channel = data.author.voice.channel
elif not m_channel:
raise UserPermissionError("Must be in voice chat.")
self.vc = data.guild.voice_client
if self.vc:
await self.vc.move_to(m_channel)
return m_channel
perms = m_channel.permissions_for(self.guild.me)
if perms.connect and perms.speak and perms.use_voice_activation:
try:
self.vc = await m_channel.connect()
if self.queue:
await self.skip_song(data)
return m_channel
except(InvalidArgument, ClientException):
self.parent.logger.exception("Error connecting to voice chat. ", exc_info=True)
return False
else:
return False
评论列表
文章目录