Skip to content
Yousef Z edited this page Dec 24, 2022 · 5 revisions

Qalib (Arabic: قالب), which means template in Arabic, is the official name of this library.

What is 🃏 Discord-Qalib?

Discord-Qalib is an extension that wraps around and extends discord.py Context instance, allowing for templated responses so that front-end facing text is separated from the source code and placed in a file in a structured manner (i.e. .xml, .json).

A simple example .xml file would be

<discord>
    <embed key="balance">
        <title>Hello {player.name}</title>
        <colour>cyan</colour>
        <fields>
            <field>
	        <title>Balance Remaining</title>
		<value>${player.balance}</value>
	    </field>
	</fields>
    </embed>
</discord>

stored as balance.xml in the templates directory

and can be used in the source code as such

from dataclasses import dataclass

from discord.ext import commands

import qalib

bot = commands.AutoShardedBot(command_prefix="!", intents=discord.Intents.all())

@dataclass
class Player:
    name: str
    balance: float

@bot.command()
@qalib.embed_manager("templates/balance.xml")
def balance(ctx, name: str):
    await ctx.rendered_send("balance", keywords={"player": Player(name, 1000.0)})
Clone this wiki locally