TTSCore: autoexit if bot is last member of a voice channel

This commit is contained in:
norohind 2022-03-28 23:30:45 +03:00
parent 10456f62e0
commit 717c750bb6
Signed by: norohind
GPG Key ID: 01C3BECC26FB59E1

View File

@ -110,6 +110,14 @@ class TTSCore(commands.Cog, Observ.Observer):
except KeyError:
pass
@commands.Cog.listener()
async def on_voice_state_update(self, member: discord.Member, before: discord.VoiceState, after: discord.VoiceState):
if after.channel is None:
members = before.channel.members
if len(members) == 1:
if members[0].id == self.bot.user.id:
await before.channel.guild.voice_client.disconnect(force=False)
async def setup(bot):
await bot.add_cog(TTSCore(bot))