fix: Add debug logging for bot initialization, guild and member retrieval, and UI component creation in LevelingCog
This commit is contained in:
parent
c7097425a7
commit
d6876f0e8a
@ -25,6 +25,8 @@ DEFAULT_LEVEL_MULTIPLIER = 35 # XP needed per level = level * multiplier
|
||||
class LevelingCog(commands.Cog):
|
||||
def __init__(self, bot: commands.Bot):
|
||||
self.bot = bot
|
||||
if not self.bot:
|
||||
print("DEBUG: Bot instance is None in LevelingCog.__init__")
|
||||
self.user_data = {} # {user_id: {"xp": int, "level": int, "last_message_time": float}}
|
||||
self.level_roles = {} # {guild_id: {level: role_id}}
|
||||
self.restricted_channels = set() # Set of channel IDs where XP gain is disabled
|
||||
@ -238,11 +240,13 @@ class LevelingCog(commands.Cog):
|
||||
# Get the guild object
|
||||
guild = self.bot.get_guild(guild_id)
|
||||
if not guild:
|
||||
print(f"DEBUG: Guild {guild_id} not found in assign_level_role")
|
||||
return False
|
||||
|
||||
# Get the member object
|
||||
member = guild.get_member(user_id)
|
||||
if not member:
|
||||
print(f"DEBUG: Member {user_id} not found in guild {guild_id} in assign_level_role")
|
||||
return False
|
||||
|
||||
# Find the highest role that matches the user's level
|
||||
@ -280,6 +284,9 @@ class LevelingCog(commands.Cog):
|
||||
if highest_role_id:
|
||||
# Get the role object
|
||||
role = guild.get_role(highest_role_id)
|
||||
if not role:
|
||||
print(f"DEBUG: Role {highest_role_id} not found in guild {guild_id} in assign_level_role")
|
||||
return False
|
||||
if role and role not in member.roles:
|
||||
try:
|
||||
# Remove any other level roles
|
||||
@ -367,6 +374,10 @@ class LevelingCog(commands.Cog):
|
||||
async def level_check(self, ctx: commands.Context, member: discord.Member = None):
|
||||
"""Check your current level and XP or another member's"""
|
||||
target = member or ctx.author
|
||||
if not target:
|
||||
print("DEBUG: Target member is None in level_check")
|
||||
await ctx.send("Error: Could not determine target member.")
|
||||
return
|
||||
user_data = self.get_user_data(target.id)
|
||||
|
||||
level = user_data["level"]
|
||||
@ -388,8 +399,15 @@ class LevelingCog(commands.Cog):
|
||||
def __init__(self, target_member: discord.Member, level: int, xp: int, xp_needed: int, next_level: int, bar: str, progress_percent: int):
|
||||
super().__init__()
|
||||
|
||||
# Debug logging for parameters
|
||||
if not target_member:
|
||||
print("DEBUG: target_member is None in LevelCheckView.__init__")
|
||||
|
||||
# Main container for all elements, providing the accent color
|
||||
main_container = ui.Container(accent_colour=None)
|
||||
if not main_container:
|
||||
print("DEBUG: ui.Container returned None in LevelCheckView")
|
||||
return
|
||||
self.add_item(main_container) # Add the main container to the view
|
||||
|
||||
# Prepare thumbnail accessory
|
||||
@ -407,8 +425,17 @@ class LevelingCog(commands.Cog):
|
||||
user_info_section.add_item(ui.TextDisplay(f"**Level:** {level}\n**XP:** {xp} / {xp_needed}"))
|
||||
|
||||
# Add remaining components directly to the main_container
|
||||
main_container.add_item(ui.Separator(spacing=discord.SeparatorSpacing.small))
|
||||
main_container.add_item(ui.TextDisplay(f"**Progress to Level {next_level}:**\n[{bar}] {progress_percent}%"))
|
||||
separator = ui.Separator(spacing=discord.SeparatorSpacing.small)
|
||||
if separator:
|
||||
main_container.add_item(separator)
|
||||
else:
|
||||
print("DEBUG: ui.Separator returned None in LevelCheckView")
|
||||
|
||||
progress_text = ui.TextDisplay(f"**Progress to Level {next_level}:**\n[{bar}] {progress_percent}%")
|
||||
if progress_text:
|
||||
main_container.add_item(progress_text)
|
||||
else:
|
||||
print("DEBUG: ui.TextDisplay returned None in LevelCheckView")
|
||||
|
||||
view = LevelCheckView(target, level, xp, xp_needed, next_level, bar, int(progress * 100))
|
||||
await ctx.send(view=view)
|
||||
@ -720,9 +747,23 @@ class LevelingCog(commands.Cog):
|
||||
main_container = ui.Container(accent_colour=discord.Color.blue())
|
||||
self.add_item(main_container)
|
||||
|
||||
main_container.add_item(ui.TextDisplay("**XP Configuration Settings**"))
|
||||
main_container.add_item(ui.TextDisplay("Current XP settings for the leveling system:"))
|
||||
main_container.add_item(ui.Separator(spacing=discord.SeparatorSpacing.small))
|
||||
title_text = ui.TextDisplay("**XP Configuration Settings**")
|
||||
if title_text:
|
||||
main_container.add_item(title_text)
|
||||
else:
|
||||
print("DEBUG: ui.TextDisplay returned None in XPConfigView (title)")
|
||||
|
||||
desc_text = ui.TextDisplay("Current XP settings for the leveling system:")
|
||||
if desc_text:
|
||||
main_container.add_item(desc_text)
|
||||
else:
|
||||
print("DEBUG: ui.TextDisplay returned None in XPConfigView (description)")
|
||||
|
||||
separator = ui.Separator(spacing=discord.SeparatorSpacing.small)
|
||||
if separator:
|
||||
main_container.add_item(separator)
|
||||
else:
|
||||
print("DEBUG: ui.Separator returned None in XPConfigView")
|
||||
|
||||
settings_to_display = [
|
||||
("XP Per Message", str(config_data["xp_per_message"])),
|
||||
@ -737,8 +778,17 @@ class LevelingCog(commands.Cog):
|
||||
setting_section.add_item(ui.TextDisplay(f"**{name}:** {value_str}"))
|
||||
main_container.add_item(setting_section)
|
||||
|
||||
main_container.add_item(ui.Separator(spacing=discord.SeparatorSpacing.small))
|
||||
main_container.add_item(ui.TextDisplay(f"Use {prefix}level config <setting> <value> to change a setting")) # Updated help text
|
||||
separator = ui.Separator(spacing=discord.SeparatorSpacing.small)
|
||||
if separator:
|
||||
main_container.add_item(separator)
|
||||
else:
|
||||
print("DEBUG: ui.Separator returned None in XPConfigView (bottom)")
|
||||
|
||||
help_text = ui.TextDisplay(f"Use {prefix}level config <setting> <value> to change a setting")
|
||||
if help_text:
|
||||
main_container.add_item(help_text)
|
||||
else:
|
||||
print("DEBUG: ui.TextDisplay returned None in XPConfigView (help)")
|
||||
|
||||
# Attempt to get the prefix
|
||||
try:
|
||||
|
Loading…
x
Reference in New Issue
Block a user