Un gerente de plantilla de Python para su bot de discordia para mantener sus incrustaciones simples y consistentes
Use el siguiente comando para instalar el templador de la embriaguez en su entorno Python:
pip install Embed-TemplatorDependiendo de su instalación de Python, es posible que deba usar una de las siguientes opciones.
Pip no está en el camino, pero Python está
python -m pip install embed-templatorPython no está en el camino
path/to/python.exe -m pip install embed-templatorUsando múltiples versiones de Python
py -m pip install embed-templatorLa forma más sencilla de usar el plantador de inserción en su proyecto es la siguiente:
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!' ))Sin embargo, el plantador de inserción puede tener un uso más avanzado y usar incrustaciones de contexto.
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!' ))Si está utilizando un sistema basado en COG, no olvide iniciar la incrustación en sus COGS con lo siguiente:
class MyBeautifulCog ( commands . Cog ):
def __init__ ( self , client ):
self . client = client
Embed . load ( self . client )Entonces podrás usarlo como los ejemplos anteriores:
@ commands . command ()
async def my ( self , ctx ):
await ctx . send (
embed = Embed ( ctx )( description = "Cabbage" )
)Si desea una configuración de incrustación avanzada, puede crear una clase de incrustación personalizada que heredará el plantador de inserción.
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"
)| ❗ | ¡Este ejemplo utiliza un CTX personalizado que tiene un seguimiento de tiempo! |
|---|
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¡Gracias por usar inserción-templator!
© 2020 copyright Edhyjox
Este repositorio tiene licencia bajo la licencia MIT. Vea la licencia para más detalles.