4 of 4
Build the ultimate bot command — a profile card generator! This combines everything you've learned into one project with multiple functions working together.
Write four functions that build a player's RPG profile card for Discord.
xp_bar(current_xp, max_xp)filled = int((current_xp / max_xp) * 10)"█" for filled and "░" for emptyxp_bar(75, 100) → "███████░░░ 75/100"get_rank(level)"🌱 Beginner""⚔️ Warrior""🔮 Mage""👑 Legend"format_badges(badge_list)"No badges yet"• (bullet separator)format_badges(["PvP", "Explorer"]) → "PvP • Explorer"create_profile(username, level, current_xp, max_xp, badges)The profile should look like:
╔══════════════════════════╗
👤 DragonSlayer99
🔮 Mage — Level 30
━━━━━━━━━━━━━━━━━━━━
XP: ███████░░░ 350/500
🏅 PvP Champ • Explorer • Builder
╚══════════════════════════╝
def xp_bar(current_xp, max_xp): # Calculate filled blocks (out of 10) # Return the bar + "current/max" pass def get_rank(level): # Return a rank based on level ranges pass def format_badges(badge_list): # Return badges joined with " • " or "No badges yet" pass def create_profile(username, level, current_xp, max_xp, badges): # Use the other 3 functions to build the profile pass # Test individual functions: print(xp_bar(75, 100)) # Output: ███████░░░ 75/100 print(xp_bar(30, 200)) # Output: █░░░░░░░░░ 30/200 print(get_rank(5)) # Output: 🌱 Beginner print(get_rank(30)) # Output: 🔮 Mage print(format_badges(["PvP Champ", "Explorer"])) # Output: PvP Champ • Explorer print(format_badges([])) # Output: No badges yet print("---") # Test the full profile: print(create_profile("DragonSlayer99", 30, 350, 500, ["PvP Champ", "Explorer", "Builder"])) print() print(create_profile("NewPlayer42", 3, 50, 100, []))
███████░░░ 75/100
█░░░░░░░░░ 30/200
🌱 Beginner
🔮 Mage
PvP Champ • Explorer
No badges yet
---
╔══════════════════════════╗
👤 DragonSlayer99
🔮 Mage — Level 30
━━━━━━━━━━━━━━━━━━━━
XP: ███████░░░ 350/500
🏅 PvP Champ • Explorer • Builder
╚══════════════════════════╝
╔══════════════════════════╗
👤 NewPlayer42
🌱 Beginner — Level 3
━━━━━━━━━━━━━━━━━━━━
XP: █████░░░░░ 50/100
🏅 No badges yet
╚══════════════════════════╝
Calculate the proportion, multiply by 10, and build the bar:
filled = int((current_xp / max_xp) * 10) empty = 10 - filled bar = "█" * filled + "░" * empty return f"{bar} {current_xp}/{max_xp}"
Use if/elif/else to check level ranges:
if level <= 10: return "🌱 Beginner" elif level <= 25: return "⚔️ Warrior" # ...
Check if the list is empty first, then use .join():
if len(badge_list) == 0: return "No badges yet" return " • ".join(badge_list)
Call your other functions and build the string:
rank = get_rank(level) bar = xp_bar(current_xp, max_xp) badge_str = format_badges(badges) # Now build the profile string with these values
def xp_bar(current_xp, max_xp): filled = int((current_xp / max_xp) * 10) empty = 10 - filled bar = "█" * filled + "░" * empty return f"{bar} {current_xp}/{max_xp}" def get_rank(level): if level <= 10: return "🌱 Beginner" elif level <= 25: return "⚔️ Warrior" elif level <= 50: return "🔮 Mage" else: return "👑 Legend" def format_badges(badge_list): if len(badge_list) == 0: return "No badges yet" return " • ".join(badge_list) def create_profile(username, level, current_xp, max_xp, badges): rank = get_rank(level) bar = xp_bar(current_xp, max_xp) badge_str = format_badges(badges) profile = "╔══════════════════════════╗\n" profile += f" 👤 {username}\n" profile += f" {rank} — Level {level}\n" profile += " ━━━━━━━━━━━━━━━━━━━━\n" profile += f" XP: {bar}\n" profile += f" 🏅 {badge_str}\n" profile += "╚══════════════════════════╝" return profile
create_profile calls three other functions.join()"█" * filled to build the progress barWrite your code below. Click Run to test locally, then click Send to Discord to have the bot post your output to the server!