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!