Description
In nw_server_status/server_status.py, the forcemonitor command does not check if the monitor channel exists before attempting to access its permissions, leading to a potential null pointer exception.
Location
File: nw_server_status/server_status.py
Lines: 209-210
Current Code
async def forcemonitor(self, ctx):
voice_channel = await self.get_guild_monitor_channel(ctx.guild)
bot_perms = voice_channel.permissions_for(ctx.me) # ❌ Null pointer if voice_channel is None
Root Cause
The method get_guild_monitor_channel() can return None (see line 112):
async def get_guild_monitor_channel(self, guild):
channel_id = await self.config.guild(guild).monitor_channel()
if not channel_id:
return None # ← Returns None if not configured
channel = guild.get_channel(channel_id)
if not channel:
return None # ← Returns None if channel deleted
return channel
However, the caller at line 209 does not check for None before accessing voice_channel.permissions_for().
Impact
- Bot crash when
/forcemonitor is used before a monitor channel is configured
AttributeError: 'NoneType' object has no attribute 'permissions_for'
- Command fails ungracefully without user-friendly error message
Fix Required
Add a null check before accessing the channel:
async def forcemonitor(self, ctx):
voice_channel = await self.get_guild_monitor_channel(ctx.guild)
if not voice_channel:
await ctx.send("❌ No monitor channel is configured. Use `[p]monitor <channel>` first.")
return
bot_perms = voice_channel.permissions_for(ctx.me)
# ... rest of the code
Priority
HIGH - Causes bot crash and poor user experience.
Testing
After fixing:
- Run
[p]forcemonitor without setting up a monitor channel first
- Verify you get a helpful error message instead of a crash
- Set up a monitor channel, then run
[p]forcemonitor again
- Verify it works correctly
Related
This is part of a comprehensive code review. See other issues for additional improvements.
Description
In
nw_server_status/server_status.py, theforcemonitorcommand does not check if the monitor channel exists before attempting to access its permissions, leading to a potential null pointer exception.Location
File:
nw_server_status/server_status.pyLines: 209-210
Current Code
Root Cause
The method
get_guild_monitor_channel()can returnNone(see line 112):However, the caller at line 209 does not check for
Nonebefore accessingvoice_channel.permissions_for().Impact
/forcemonitoris used before a monitor channel is configuredAttributeError: 'NoneType' object has no attribute 'permissions_for'Fix Required
Add a null check before accessing the channel:
Priority
HIGH - Causes bot crash and poor user experience.
Testing
After fixing:
[p]forcemonitorwithout setting up a monitor channel first[p]forcemonitoragainRelated
This is part of a comprehensive code review. See other issues for additional improvements.