Skip to content

1. How To Use

Yousef Z edited this page Dec 25, 2022 · 23 revisions

Here we will be talking about how to use the interface of the QalibContext

Simple Usage

This is a simple XML file that contains a barebones embed

<discord>
    <embed key="test_key">
        <title>Hello World</title>
        <colour>cyan</colour>
        <fields>
            <field>
                <name>Field 1</name>
                <value>This is the first field in the embed that is mandatory</value>
            </field>
        </fields>
    </embed>
</discord>

Lets dissect this, piece by piece. First off, we have the <discord> tag which is the container (ElementTree) for all the <embed> elements. We can have a variable number of <embed> elements and they are uniquely identified by their key attribute such as <embed key="test_key">, which is used to identify this embed, in this case test_key uniquely identifies this embed.

We then use the the components of the embed class, so the 3 mandatory elements of an embed that is required to render it is the <title>, <colour>/<color>, and at least one <field> in the <fields> container, which contain a <name>, and a <value>.

Using more of the attributes that can associated with an embed

Each embed can be extended to leverage more the things that an embed can offer such as:

  1. Description
  2. Type
  3. Timestamp
  4. Url
  5. Footer
    1. Text
    2. Icon
  6. Thumbnail
  7. Image
  8. Author
    1. Name
    2. Icon
    3. Url
<discord>
    <embed key="test_key">
        <title>Test</title>
        <description>Test Description</description>
        <type>rich</type>
        <colour>magenta</colour>
        <timestamp>{todays_date}</timestamp>
        <url>https://www.discord.com</url>
        <fields>
            <field>
                <name>Test Field</name>
                <text>Test Text</text>
            </field>
        </fields>
        <footer>
            <text>Test Footer</text>
            <icon>https://cdn.discordapp.com/embed/avatars/0.png</icon>
        </footer>
        <thumbnail>https://cdn.discordapp.com/embed/avatars/0.png</thumbnail>
        <image>https://cdn.discordapp.com/embed/avatars/0.png</image>
        <author>
            <name>Test Author</name>
            <icon>https://cdn.discordapp.com/embed/avatars/0.png</icon>
            <url>https://discordapp.com</url>
        </author>
    </embed>
</discord>

First make the XML files containing your embeds in a separate directory (for the sake of simplicity, it will be called templates).

and then can be used by an EmbedManager instance

import discord
from discord.ext import commands

import qalib

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

@bot.command()
@qalib.embed_manager("templates/test.xml")
async def test(ctx):

    await ctx.rendered_send("test_key", keywords={
        "todays_date": datetime.datetime.now()
    })
Clone this wiki locally