mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 11:18:54 -05:00
[Audio] Remove players which no longer have a guild. (#2414)
Cleanup players when the bot has one for a guild it leaves. Bumps Red-Lavalink to v0.2.2
This commit is contained in:
parent
f91e0a6546
commit
4b831a634a
@ -2667,3 +2667,20 @@ class Audio(commands.Cog):
|
|||||||
self._cleaned_up = True
|
self._cleaned_up = True
|
||||||
|
|
||||||
__del__ = __unload
|
__del__ = __unload
|
||||||
|
|
||||||
|
async def on_guild_remove(self, guild: discord.Guild):
|
||||||
|
"""
|
||||||
|
This is to clean up players when
|
||||||
|
the bot either leaves or is removed from a guild
|
||||||
|
"""
|
||||||
|
channels = {
|
||||||
|
x # x is a voice_channel
|
||||||
|
for y in [g.voice_channels for g in self.bot.guilds]
|
||||||
|
for x in y # y is a list of voice channels
|
||||||
|
} # Yes, this is ugly. It's also the most performant and commented.
|
||||||
|
|
||||||
|
zombie_players = {p for p in lavalink.player_manager.players if p.channel not in channels}
|
||||||
|
# Do not unroll to combine with next line.
|
||||||
|
# Can result in iterator changing size during context switching.
|
||||||
|
for zombie in zombie_players:
|
||||||
|
await zombie.destroy()
|
||||||
|
|||||||
@ -40,7 +40,7 @@ install_requires =
|
|||||||
multidict==4.5.2
|
multidict==4.5.2
|
||||||
python-levenshtein-wheels==0.13.1
|
python-levenshtein-wheels==0.13.1
|
||||||
pyyaml==3.13
|
pyyaml==3.13
|
||||||
red-lavalink==0.2.1
|
red-lavalink==0.2.2
|
||||||
schema==0.6.8
|
schema==0.6.8
|
||||||
websockets==7.0
|
websockets==7.0
|
||||||
yarl==1.3.0
|
yarl==1.3.0
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user