Skip to main content

A Python Template manager for your discord bot to keep your embeds simple & consistent.

Project description

Embed Templator

PyPI - Downloads PyPI PyPI - Format PyPI - Python Version GitHub code size in bytes GitHub repo size GitHub last commit

A Python Template manager for your discord bot to keep your embeds simple & consistent

Installation

Use The following command to install Embed-Templator into your python environment:

pip install Embed-Templator
didn't works?

Depending on your python installation, you might need to use one of the following.

pip isn't in the path but python is

python -m pip install embed-templator

python isn't in the path

path/to/python.exe -m pip install embed-templator

Using multiple python versions

py -m pip install embed-templator

Usage

Simplest

The simplest way to use the Embed templator in your project is the following:

from embed_templator import Embed

# Loading your client instance withing the embed templator.
Embed.load(client)


@client.command()
async def ping(ctx):
    # Use it like a regular Embed.
    await ctx.send(embed=Embed(description='pong!'))

Context Embeds

However, the embed templator can have more advanced usage, and use context embeds.

from embed_templator import Embed

client = ...

# Note that auto_author requires the ctx to be passed at embeds init.
Embed.load(client, auto_author=True)


@client.command()
async def ping(ctx):
    # Use it like a regular Embed.
    await ctx.send(embed=Embed(ctx)(description='pong!'))

Cogs

If you are using a cog based system, don't forget to init the embed in your cogs with the following:

class MyBeautifulCog(commands.Cog):

    def __init__(self, client):
        self.client = client
        
        Embed.load(self.client)

Then you'll be able to use it like the previous examples:

    @commands.command()
    async def my(self, ctx):

        await ctx.send(
            embed=Embed(ctx)(description="Cabbage")
        )

Advanced Usage

If you want an advanced embed configuration, you can create a custom embed class that will inherit the embed templator.

from __future__ import annotations
import embed_templator


class Embed(embed_templator.Embed):
    
    def setup(self) -> Embed:
        return self.set_footer(
            text=f"{self.ctx.command} | more info @ {self.ctx.prefix}help"
        )

You can also use the `update` method for last changes in the embed, better it will be sent.
:exclamation: This example uses a custom ctx that have time tracking !
from __future__ import annotations
import embed_templator


class Embed(embed_templator.Embed):

    def setup(self) -> Embed:
        return self.set_author(
            name=f"Requested by {self.ctx.author} 🚀",
            icon_url=self.ctx.author.avatar_url
        )

    def update(self) -> Embed:
        self.set_footer(
            icon_url=self.client.user.avatar_url,
            text='   '.join(
                (
                    f"⚙️ {self.ctx.time.elapsed()}",
                    f"⏳ {self.client.latency}",
                    f"🔑 {self.ctx.prefix}help",
                )
            )
        )

        return self

Thanks for using Embed-Templator!

License

© 2020 copyright Edhyjox

This repository is licensed under the MIT License. See LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

embed-templator-1.0.4.tar.gz (5.2 kB view hashes)

Uploaded Source

Built Distribution

embed_templator-1.0.4-py3-none-any.whl (6.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page