diff --git a/botbotbot/voice.py b/botbotbot/voice.py index 20ca4b8..2299151 100644 --- a/botbotbot/voice.py +++ b/botbotbot/voice.py @@ -45,9 +45,14 @@ class VoiceBot: if guild is None: continue - logger.info("Random connect.") - voice_chan = random.choice(guild.voice_channels) - await self.connect_voice(voice_chan) + if random.random() < 50 / 100: + logger.info("Random connect.") + voice_chan = random.choice(guild.voice_channels) + await self.connect_voice(voice_chan) + else: + logger.info("Random disconnect.") + await self.disconnect_voice(guild) + await asyncio.sleep(3600 * random.random()) async def connect_voice( @@ -94,11 +99,14 @@ class VoiceBot: async def connect_voice_chan( self, channel: discord.VoiceChannel | discord.StageChannel ) -> discord.VoiceClient: - for vc in self.bot.voice_clients: - if isinstance(vc, discord.VoiceClient) and vc.guild == channel.guild: - await vc.disconnect() + await self.disconnect_voice(channel.guild) return await channel.connect() + async def disconnect_voice(self, guild: discord.Guild) -> None: + for vc in self.bot.voice_clients: + if isinstance(vc, discord.VoiceClient) and vc.guild == guild: + await vc.disconnect() + async def join_voice(self, ctx: discord.ApplicationContext) -> None: if ctx.user.voice: await ctx.respond(