Advertisement
NaroxEG

EasyPIL + DPY

Sep 26th, 2023
749
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.79 KB | None | 0 0
  1. import discord
  2. from discord.ext import commands
  3. from easy_pil import Editor, load_image_async, Font
  4.  
  5. client = commands.Bot(command_prefix="-", intents=discord.Intents.default())
  6. tree = client.tree
  7.  
  8.  
  9. @client.event
  10. async def on_ready():
  11.     synced = await tree.sync()
  12.     print(f"Synced {len(synced)} Command(s)")
  13.  
  14. levels = {
  15.     "745601141827567737": {
  16.         "level": 12,
  17.         "cXP": 500,
  18.         "rXP": 1000
  19.     },
  20.     "941082828312027248": {
  21.         "level": 50,
  22.         "cXP": 20000,
  23.         "rXP": 21000
  24.     }
  25. }
  26.  
  27.  
  28. @tree.command(name="level", description="shows user rank data")
  29. async def _level(interaction: discord.Interaction, user: discord.User):
  30.  
  31.     level = levels[str(user.id)]["level"]
  32.     cXP = levels[str(user.id)]["cXP"]
  33.     rXP = levels[str(user.id)]["rXP"]
  34.     percentage = cXP / rXP
  35.  
  36.     card = Editor("./imgs/bg.png")
  37.     avatar = await load_image_async(user.display_avatar.url)
  38.     cAvatar = Editor(avatar).resize((200, 200)).circle_image()
  39.     font = Font("./fonts/onestroke.TTF", size=40)
  40.  
  41.     card.paste(cAvatar, (30, 25))
  42.  
  43.     card.rectangle((250, 120), width=615 * percentage,
  44.                    height=40, fill="#FACF11", radius=20)
  45.  
  46.     card.text(
  47.         (252, 62),
  48.         f"{user.name}",
  49.         font=font, color="#000"
  50.     )
  51.     card.text(
  52.         (250, 60),
  53.         f"{user.name}",
  54.         font=font, color="#FACF11"
  55.     )
  56.  
  57.     card.text(
  58.         (262, 172),
  59.         f"Level: {level}" + "    " + f"XP: {cXP} / {rXP}",
  60.         font=font, color="#000"
  61.     )
  62.     card.text(
  63.         (260, 170),
  64.         f"Level: {level}" + "    " + f"XP: {cXP} / {rXP}",
  65.         font=font, color="#FACF11"
  66.     )
  67.  
  68.     file = discord.File(card.image_bytes, filename="card.png")
  69.     await interaction.response.send_message(file=file)
  70.  
  71. client.run("TOKEN")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement