Um gerenciador de modelos Python para o seu Bot Discord para manter suas incorporações simples e consistentes
Use o seguinte comando para instalar o integrado-temperatador no ambiente Python:
pip install Embed-TemplatorDependendo da instalação do Python, pode ser necessário usar um dos seguintes.
Pip não está no caminho, mas Python é
python -m pip install embed-templatorPython não está no caminho
path/to/python.exe -m pip install embed-templatorUsando várias versões python
py -m pip install embed-templatorA maneira mais simples de usar o templador incorporado em seu projeto é o seguinte:
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!' ))No entanto, o templador incorporado pode ter uso mais avançado e usar incorporações 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!' ))Se você estiver usando um sistema baseado em COG, não se esqueça de iniciar a incorporação em suas engrenagens com o seguinte:
class MyBeautifulCog ( commands . Cog ):
def __init__ ( self , client ):
self . client = client
Embed . load ( self . client )Então você poderá usá -lo como os exemplos anteriores:
@ commands . command ()
async def my ( self , ctx ):
await ctx . send (
embed = Embed ( ctx )( description = "Cabbage" )
)Se você deseja uma configuração de incorporação avançada, pode criar uma classe incorporada personalizada que herdará o Templador Incorporado.
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 exemplo usa um CTX personalizado com rastreamento de tempo! |
|---|
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 selfObrigado por usar o Templator de Embed!
© 2020 copyright Edhyjox
Este repositório é licenciado sob a licença do MIT. Consulte a licença para obter detalhes.