music.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:Bonfire 作者: Phxntxm 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号