Fix star add issues with deleted channels

This commit is contained in:
Zeva Rose 2022-04-19 11:47:38 -06:00
parent 785f67c9c4
commit a20449f7b2

View file

@ -2,7 +2,6 @@
import logging import logging
from dis_snek import InteractionContext, Permissions, Scale, Snake from dis_snek import InteractionContext, Permissions, Scale, Snake
from dis_snek.client.utils.misc_utils import find
from dis_snek.models.discord.channel import GuildText from dis_snek.models.discord.channel import GuildText
from dis_snek.models.discord.components import ActionRow, Select, SelectOption from dis_snek.models.discord.components import ActionRow, Select, SelectOption
from dis_snek.models.discord.message import Message from dis_snek.models.discord.message import Message
@ -130,8 +129,21 @@ class StarboardCog(Scale):
return return
channel_list = [] channel_list = []
to_delete = []
for starboard in starboards: for starboard in starboards:
channel_list.append(find(lambda x: x.id == starboard.channel, ctx.guild.channels)) channel = await ctx.guild.fetch_channel(starboard.channel)
if channel:
channel_list.append(channel)
else:
to_delete.append(starboard)
for starboard in to_delete:
await starboard.delete()
select_channels = []
for idx, x in enumerate(channel_list):
if x:
select_channels.append(SelectOption(label=x.name, value=str(idx)))
select_channels = [ select_channels = [
SelectOption(label=x.name, value=str(idx)) for idx, x in enumerate(channel_list) SelectOption(label=x.name, value=str(idx)) for idx, x in enumerate(channel_list)