From b4608e526c785ccc9b7b35764e7b7238df08ed5a Mon Sep 17 00:00:00 2001 From: Alex <58824393+vertyco@users.noreply.github.com> Date: Wed, 27 Oct 2021 17:11:34 -0400 Subject: [PATCH] handle deleted channels silently (#255) If a channel is deleted, when doggo comes to woof and that channel no longer exists it should delete the channel id from the config and pick a new one. and it will just ignore a deleted channel if pets command is used. --- pupper/pupper.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pupper/pupper.py b/pupper/pupper.py index cbd79f0..83b27d8 100644 --- a/pupper/pupper.py +++ b/pupper/pupper.py @@ -47,7 +47,8 @@ class Pupper(commands.Cog): channel_names = [] for channel_id in guild_data["channel"]: channel_obj = self.bot.get_channel(channel_id) - channel_names.append(channel_obj.name) + if channel_obj: + channel_names.append(channel_obj.name) space = "\N{EN SPACE}" toggle = "Active" if guild_data["toggle"] else "Inactive" @@ -94,7 +95,7 @@ class Pupper(commands.Cog): @pets.command() async def cooldown(self, ctx, seconds: int = None): - """Set the pet appearance cooldown in seconds. + """Set the pet appearance cooldown in seconds. 300s/5 minute minimum. Default is 3600s/1 hour.""" @@ -241,6 +242,11 @@ class Pupper(commands.Cog): rando_channel = random.choice(guild_data["channel"]) await asyncio.sleep(random.randint(60, 480)) rando_channel_obj = self.bot.get_channel(rando_channel) + if not rando_channel_obj: + async with self.config.guild(message.guild).all() as data: + data["channels"].remove(rando_channel) + rando_channel = random.choice(data["channel"]) + rando_channel_obj = self.bot.get_channel(rando_channel) borf_msg = await rando_channel_obj.send(guild_data["hello_msg"]) pets = "👋" pets_action = {"veryfastpats": "👋"}