From 42356746686e49387c3f6309faad8bbef89c3884 Mon Sep 17 00:00:00 2001 From: aikaterna <20862007+aikaterna@users.noreply.github.com> Date: Sat, 2 Feb 2019 18:40:29 -0800 Subject: [PATCH] [V3 NoLinks] Remove deleted channel ids --- nolinks/nolinks.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/nolinks/nolinks.py b/nolinks/nolinks.py index 7916918..a3fca41 100644 --- a/nolinks/nolinks.py +++ b/nolinks/nolinks.py @@ -76,9 +76,21 @@ class NoLinks(BaseCog): """List the channels being watched.""" channel_list = await self.config.guild(ctx.guild).watching() msg = "Links will be removed in:\n" - for channel in channel_list: - channel_obj = self.bot.get_channel(channel) - msg += f"{channel_obj.mention}\n" + if not channel_list: + msg += "No channels." + else: + remove_list = [] + for channel in channel_list: + channel_obj = self.bot.get_channel(channel) + if not channel_obj: + remove_list.append(channel) + else: + msg += f"{channel_obj.mention}\n" + if remove_list: + new_list = [x for x in channel_list if x not in remove_list] + await self.config.guild(ctx.guild).watching.set(new_list) + if len(remove_list) == len(channel_list): + msg += "No channels." await ctx.send(msg) @nolinks.command()