Skip to content

Fix AttributeError in log_uncached_deleted_message when channel is None#3499

Closed
oliveman-au wants to merge 1 commit intopython-discord:mainfrom
oliveman-au:fix/modlog-attributeerror-uncached-delete
Closed

Fix AttributeError in log_uncached_deleted_message when channel is None#3499
oliveman-au wants to merge 1 commit intopython-discord:mainfrom
oliveman-au:fix/modlog-attributeerror-uncached-delete

Conversation

@oliveman-au
Copy link
Copy Markdown
Contributor

self.bot.get_channel() can return None if the channel isn't in the bot's cache, but channel.category was being accessed immediately after with no None check, causing an AttributeError.

This is particularly impactful because log_uncached_deleted_message is called for every deleted message that isn't in the cache, which on a large server happens constantly. Every one of those events would silently crash the handler instead of logging.

Added an early return with a trace log if the channel can't be found, matching the pattern used elsewhere in the codebase.

@oliveman-au oliveman-au requested a review from mbaruh as a code owner April 24, 2026 06:06
Copy link
Copy Markdown
Member

@jb3 jb3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could probably be a higher log level, we should have some way of seeing how frequently this is happening.

@wookie184
Copy link
Copy Markdown
Contributor

I believe this is unnecessary as the check is already done in is_channel_ignored:

if isinstance(channel, int):
channel = self.bot.get_channel(channel)
# Ignore not found channels, DMs, and messages outside of the main guild.
if not channel or channel.guild is None or channel.guild.id != GuildConstant.id:
return True

It's nice to have this code written in a way that a type checker can understand, but adding a check that will never trigger makes the code less clear.

I would support making this more type checker friendly, but that would need more discussion and I don't think this is the neatest approach so I will close this.

@wookie184 wookie184 closed this May 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants