From bcca864d0206ea9e5e9e433d9d818b85269d983a Mon Sep 17 00:00:00 2001 From: SeaswimmerTheFsh Date: Mon, 19 Feb 2024 18:51:59 -0500 Subject: [PATCH] feat(tts): made pylav check happen on message invocation instead of on cog load --- tts/tts.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/tts/tts.py b/tts/tts.py index 1c9fdca..2109007 100644 --- a/tts/tts.py +++ b/tts/tts.py @@ -8,7 +8,6 @@ import logging from discord import Message -from discord.ext import tasks from redbot.core import Config, commands from redbot.core.bot import Red @@ -28,19 +27,9 @@ class TTS(commands.Cog): announce = False, voice_channels = True ) - self.check_pylav.start() - - @tasks.loop(seconds=5) - async def check_pylav(self): - await self.bot.wait_until_red_ready() - pylav = self.bot.get_cog("PyLavPlayer") - self.check_pylav.stop() - if pylav is None: - await self.bot.send_to_owners("You need to install PyLav to use the TTS cog.\nThe cog has been automatically unloaded.\nSee https://github.com/PyLav/Red-Cogs") - await self.bot.remove_cog("TTS") - raise RuntimeError("You need to install PyLav to use this cog. See https://github.com/PyLav/Red-Cogs") async def on_message(self, message: Message): + await self.bot.wait_until_red_ready() if message.author.bot: return if message.guild is None: @@ -50,6 +39,11 @@ class TTS(commands.Cog): if any(message.content.startswith(prefix) for prefix in valid_prefixes): return if message.channel.id in await self.config.guild(message.guild).enabled_channels(): + pylav = self.bot.get_cog("PyLavPlayer") + if pylav is None: + self.logger.error("PyLav is not loaded, so TTS is not available.") + await message.reply("PyLav is not loaded, so TTS is not available.\nPlease report this to the bot owner.\nIf you are the bot owner, see [https://github.com/PyLav/Red-Cogs](PyLav/RedCogs) for more information.") + return #TODO - add PyLav integration return