Skip to content

Fix incorrect None check in react_roles - use proper exception handling#130

Merged
psykzz merged 2 commits intomainfrom
claude/fix-incorrect-none-check
Mar 28, 2026
Merged

Fix incorrect None check in react_roles - use proper exception handling#130
psykzz merged 2 commits intomainfrom
claude/fix-incorrect-none-check

Conversation

@Claude
Copy link
Copy Markdown
Contributor

@Claude Claude AI commented Mar 28, 2026

Discord.py's fetch_message() never returns None - it either returns a Message object or raises exceptions (discord.NotFound, discord.Forbidden, discord.HTTPException). The code incorrectly checked if not message: after fetch calls, preventing proper error handling.

Changes

  • add_react command (lines 55-65): Replace None check with try-except blocks
  • remove_react command (lines 97-107): Apply same exception handling pattern

Before

message = await channel.fetch_message(message_id)
if not message:  # Never triggers - fetch_message raises exceptions
    await ctx.send("That message doesn't exist anymore.", ephemeral=True)
    return

After

try:
    message = await channel.fetch_message(message_id)
except discord.NotFound:
    await ctx.send("That message doesn't exist anymore.", ephemeral=True)
    return
except discord.Forbidden:
    await ctx.send("No permission to access that message.", ephemeral=True)
    return
except discord.HTTPException as e:
    await ctx.send(f"Failed to fetch message: {e}", ephemeral=True)
    return

This prevents unhandled exceptions when messages are deleted and matches the pattern used in party/party.py and game_embed/game_embed.py.

@Claude Claude AI changed the title [WIP] Fix incorrect None check in fetch_message error handling Fix incorrect None check in react_roles - use proper exception handling Mar 28, 2026
@Claude Claude AI requested a review from psykzz March 28, 2026 10:54
@psykzz psykzz marked this pull request as ready for review March 28, 2026 11:12
@psykzz psykzz merged commit 522b5e1 into main Mar 28, 2026
2 checks passed
@psykzz psykzz deleted the claude/fix-incorrect-none-check branch March 28, 2026 11:12
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.

🐛 Incorrect None check in react_roles - fetch_message never returns None

2 participants