From 2373a7b19c172666ac99b8d277ee4fb8cbb77e67 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Wed, 22 Mar 2023 15:57:10 +0000 Subject: [PATCH] All that bloat for nowt --- cogs/events.py | 11 +++++++++-- utils/client.py | 21 +++++++++++---------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/cogs/events.py b/cogs/events.py index b2369c2..cd77b60 100644 --- a/cogs/events.py +++ b/cogs/events.py @@ -234,18 +234,23 @@ class Events(commands.Cog): file = Path.cwd() / "assets" / "it-just-works.ogg" if message.author.voice is not None and message.author.voice.channel is not None: voice: discord.VoiceClient = None - if message.guild.me.voice is not None: + if message.guild.voice_client is not None: + console.log("Disconnecting") try: await _dc(message.guild.voice_client) except discord.HTTPException: pass - voice = await message.author.voice.channel.connect() + console.log("connecting") + voice = await message.author.voice.channel.connect(timeout=10, reconnect=False) + console.log("connected") if voice.channel != message.author.voice.channel: + console.log("moving") await voice.move_to(message.author.voice.channel) if message.guild.me.voice.self_mute or message.guild.me.voice.mute: await _dc(voice) + console.log("disconnecting bad") await message.channel.trigger_typing() await message.reply("Unmute me >:(", file=discord.File(file)) else: @@ -258,7 +263,9 @@ class Events(commands.Cog): if e is not None: console.log(f"Error playing audio: {e}") + console.log("sourcing") src = discord.FFmpegPCMAudio(str(file.absolute()), stderr=subprocess.DEVNULL) + console.log("Playing audio") voice.play( src, after=after diff --git a/utils/client.py b/utils/client.py index 1be0dc8..4fd4d62 100644 --- a/utils/client.py +++ b/utils/client.py @@ -60,16 +60,17 @@ class Bot(commands.Bot): if getattr(self, "web", None) is not None: self.console.log("Closing web server...") await self.web["server"].shutdown() - self.web["task"].cancel() - self.console.log("Web server closed.") - try: - await self.web["task"] - except asyncio.CancelledError: - pass - del self.web["server"] - del self.web["config"] - del self.web["task"] - del self.web + if hasattr(self, "web"): + self.web["task"].cancel() + self.console.log("Web server closed.") + try: + await self.web["task"] + except asyncio.CancelledError: + pass + del self.web["server"] + del self.web["config"] + del self.web["task"] + del self.web try: await super().close() except asyncio.TimeoutError: