← Back to Functions
šŸ°

RPG Profile Card

Discord Bot

4 of 4

Discord Bot Exercise 4: RPG Profile Card

Build the ultimate bot command — a profile card generator! This combines everything you've learned into one project with multiple functions working together.


Your Task

Write four functions that build a player's RPG profile card for Discord.

Function 1: xp_bar(current_xp, max_xp)

  • Takes current XP and max XP
  • Returns a visual progress bar string
  • Calculate how many filled blocks out of 10: filled = int((current_xp / max_xp) * 10)
  • Use "ā–ˆ" for filled and "ā–‘" for empty
  • Example: xp_bar(75, 100) → "ā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–‘ā–‘ā–‘ 75/100"

Function 2: get_rank(level)

  • Takes a player's level
  • Returns a rank title string based on the level:
    • Level 1–10: "🌱 Beginner"
    • Level 11–25: "āš”ļø Warrior"
    • Level 26–50: "šŸ”® Mage"
    • Level 51+: "šŸ‘‘ Legend"

Function 3: format_badges(badge_list)

  • Takes a list of badge names
  • If the list is empty, return "No badges yet"
  • Otherwise, return the badges joined with • (bullet separator)
  • Example: format_badges(["PvP", "Explorer"]) → "PvP • Explorer"

Function 4: create_profile(username, level, current_xp, max_xp, badges)

  • Takes all the player info
  • Calls the other three functions to assemble the full card
  • Returns a formatted profile string

The profile should look like:

╔══════════════════════════╗
  šŸ‘¤ DragonSlayer99
  šŸ”® Mage — Level 30
  ━━━━━━━━━━━━━━━━━━━━
  XP: ā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–‘ā–‘ā–‘ 350/500
  šŸ… PvP Champ • Explorer • Builder
ā•šā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•

Starter Code

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, []))

Expected Output

ā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–ˆā–‘ā–‘ā–‘ 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
ā•šā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•

Hints

Hint 1 — xp_bar

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}"
Hint 2 — get_rank

Use if/elif/else to check level ranges:

if level <= 10: return "🌱 Beginner" elif level <= 25: return "āš”ļø Warrior" # ...
Hint 3 — format_badges

Check if the list is empty first, then use .join():

if len(badge_list) == 0: return "No badges yet" return " • ".join(badge_list)
Hint 4 — create_profile

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
Solution
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

Topics Practiced

  • Function composition — create_profile calls three other functions
  • Conditionals — if/elif/else for rank tiers
  • Lists — badge list, checking empty, .join()
  • Math — calculating proportions for the XP bar
  • String multiplication — "ā–ˆ" * filled to build the progress bar
  • String building — assembling a complex multi-line output
  • Return values — every function returns a piece the main function uses

Try it — then send to Discord!

Write your code below. Click Run to test locally, then click Send to Discord to have the bot post your output to the server!

Code: RPG Profile Card

Loading Python runtime...
Python ...Discord Bot Mode
Loading...
Output
Click "Run" to execute your code...