Skip to content

Commit

Permalink
fix: Ignore Non-Messageable Channels (#879)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkriste authored Oct 19, 2024
1 parent 2a386df commit 6054a0a
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions ClemBot.Bot/bot/services/emote_board_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
"***GOD-TIER***",
]

VALID_CHANNEL_TYPES = (
discord.Thread,
discord.TextChannel,
discord.VoiceChannel,
discord.StageChannel,
)


class EmoteBoardService(BaseService):
"""
Expand Down Expand Up @@ -58,7 +65,10 @@ async def on_reaction_add(self, event: RawReactionActionEvent) -> None:
assert guild is not None

channel = guild.get_channel_or_thread(event.channel_id)
assert channel is not None and isinstance(channel, discord.abc.Messageable)
assert channel is not None

if not isinstance(channel, VALID_CHANNEL_TYPES):
return

message = await channel.fetch_message(event.message_id)

Expand Down Expand Up @@ -116,7 +126,10 @@ async def on_message_edit(self, event: RawMessageUpdateEvent) -> None:
assert guild is not None

channel = guild.get_channel_or_thread(event.channel_id)
assert channel is not None and isinstance(channel, discord.abc.Messageable)
assert channel is not None

if not isinstance(channel, VALID_CHANNEL_TYPES):
return

# Attempt to fetch the message, ignore if we do not have permissions.
message: discord.Message
Expand Down Expand Up @@ -153,7 +166,7 @@ async def on_message_edit(self, event: RawMessageUpdateEvent) -> None:
if not (channel := guild.get_channel_or_thread(channel_id)):
continue

assert isinstance(channel, discord.abc.Messageable)
assert isinstance(channel, VALID_CHANNEL_TYPES)
embed_msg = await channel.fetch_message(message_id)
embed = await self._as_embed(
message,
Expand Down Expand Up @@ -181,7 +194,7 @@ async def on_message_delete(self, event: RawMessageDeleteEvent) -> None:
if not (channel := guild.get_channel_or_thread(channel_id)):
continue

assert isinstance(channel, discord.abc.Messageable)
assert isinstance(channel, VALID_CHANNEL_TYPES)
embed_msg = await channel.fetch_message(message_id)
await embed_msg.delete()
except NotFound: # Skips over the item if fetch_message() raises `NotFound`
Expand Down Expand Up @@ -217,7 +230,7 @@ async def _create_post(
for channel_id in board.channels:
if not (channel := guild.get_channel_or_thread(channel_id)):
continue
assert isinstance(channel, discord.abc.Messageable)
assert isinstance(channel, VALID_CHANNEL_TYPES)
message = await channel.send(embed=embed)
post.channel_message_ids[channel_id] = message.id

Expand Down Expand Up @@ -252,7 +265,7 @@ async def _update_post(
if not (channel := guild.get_channel_or_thread(channel_id)):
continue

if not isinstance(channel, discord.abc.Messageable):
if not isinstance(channel, VALID_CHANNEL_TYPES):
continue

embed_msg = await channel.fetch_message(message_id)
Expand Down

0 comments on commit 6054a0a

Please sign in to comment.